Anda di halaman 1dari 5

COMPUTER PROGRAMMING

ASSIGNMENT 1

Submitted By,
BATCH - 2
Roll No : 11 - 20

COMPUTER PROGRAMMING
ASSIGNMENT 1

1
Qn 1. Which of the following are invalid variable names and why?
• n$bc
• matrix 1
• and abc
• float
Ans.

Variable Name Valid or Not Remark


Dollar sign is illegal. Variable names
n$bc Not Valid may only consist of letters, digits and
the underscore (_).
Blank space is not permitted in a
variable name. Here a blank space is
matrix 1 Not Valid
present between ‘matrix’ and the digit
‘1’.
Blank space is not permitted in a
and abc Not Valid variable name. Here a blank space is
present between ‘and’ and ‘abc’.
A Variable name must not be the same
float Not Valid as a keyword. Here ‘float’ is a
keyword.

Qn 2. Mention any four unary ‘C’ operations and their uses.

Ans. The operators which operates on a single operand is known as a


unary operator. Some unary operators are discussed below.

1. INCREMENT OPERATOR : The increment operator (‘++’)


causes its operand to be increased by one.
Eg : m = 5;
Y = ++m;

2. DECREMENT OPERATOR : The decrement operator (‘- -‘)


causes its operand to be decreased by one.
Eg : m = 5;
Y = - - m;

3. SIZEOF OPERATOR : The ‘sizeof’ is a compile time


operator and, when used with an operand, it returns the number of bytes the

2
operand occupies. The operand may be a variable, a constant or a data type
qualifier.
Eg : m = sizeof(long int);

4. ADDRESS OPERATOR : The address operator ‘&’ is used


to get the address of a variable.
Eg : m = &n;

Qn 3. What is wrong with the following code?

If (i=0)
Print (“Zero”);
Else
Printf (“Non-Zero”);

Ans. In the given programming code, in the IF statement, the test


expression is given as (i=0). This is not a test expression. This is an
assignment expression. Because here instead of equality operator,
assignment operator is used. Also in the printing statement, instead of the
function ‘printf’, print is given. This is not an output function in C
programming. Both these will result in errors in the program code. The
corrected program code is given below.
If (i==0)
Printf (“Zero”);
Else
Printf (“Non-Zero”);

Qn 4. What are the rules of syntax according to which valid identifiers are
defined in ‘C’ ?

Ans. Identifiers can be defined as the name given to user defined


components in program such as variables, constants, structures etc.. These
are user defined names and consist of a sequence of letters and digits, with a
letter as a first character. Both uppercase and lowercase letters are
permitted, although lowercase letters are commonly used. The underscore
character is also permitted in identifier. C put forward certain rules for
naming identifiers. The following are the rules.
1. First character must be an alphabet ( or underscore ).
2. Must consist of only letters, digits or underscore.

3
3. Only first 32 characters are significant in most compilers. So
use identifiers that are smaller than 32 characters in length.
4. Cannot use a keyword
5. Must not contain white space.

Qn 5. A ‘C’ program contains the real constant 123C5. Is it valid or not ? If


not, why ?

Ans. The given real constant 123C5 is not valid. The character C is illegal
in a real constant. Real constant may only consist of Integer numbers,
decimal notation and exponential notation.
Integer numbers are inadequate to represent quantities that vary
comtinuously, such as distance, height, temperature, prices and so on. These
quantities are represented by numbers containing fractional part like 17.548.
Such numbers are called real constants or floating point constants.

Qn 6. List the major functions of an operating system.

Ans. Operating system (OS) acts an an intermediate layer between the


application programs and the computer hardware. We can say that the
operating system is the administrator of the computer. In modern
terminology OSs are generally referred to as platforms. The main functions
of the operating system are
1. Process management
2. Memory management
3. I/O management
4. Job scheduling and
5. Data transfer etc..
In general, an operating system serves as the administrator of
The computer system. It manages the resources like memory, I/O devices,
processor etc..
Generally, operating systems have a layered architecture. Each layer
has specific functions. The inner core of the OS is called kernel.
The kernel is a hardware dependent part. Hence the same OS used in
computers of different hardware configuration have different kernel.

4
*******************

Anda mungkin juga menyukai