II-18 Programming Concepts
int main()
{
printf("Demo of return keyword");
return 0; /* '0' implies successful execution of program*/
}
16. What is the difference between %fand %gcontrol strings? Whether both can be used for 
representing float numbers?
Ans: The format string %f or %g is used to represent floating point number or real number in the form
of fraction, i.e., decimal notation. Precise results are obtained by %f. The precision indicates the number of
significant digits. In case precision is missing, i.e. for zero precision, fractional part appears with six digits.
With %g the real number or floating point number appears up to two decimal digits after decimal
point. Depending upon the applications we, therefore, can use one of them to represent the floats.
17.What do you mean by type conversion? Why is it necessary?
Ans: Type conversion converts one type of data into another type.
1. Assigning incompatible data types.
Example:
int x = 3.5;
Here, the fraction part will not be assigned to integer variable and the part will be lost. The integer
is 2-byte length data type without fractional part and float is 4-byte length data type with frac-
tional part. We can use 'float' instead.
2. Assigning out of range value.
For example, suppose that you assign 35425 to int x; you will not get expected result, because
35425 is larger than short integer range.
We may use ‘long instead.
3. Sometimes a programmer needs the result in a certain data type; for example, division of 5 with
2 should return float value. Practically, the compiler always returns integer values because
both the arguments are of integer data type.
To correct it, we use (float)5/2in the program.
18.What is wrapping around?
Ans: When the value of variable goes beyond its limit, the compiler would not flag any error mes-
sage. It just wraps around the value of a variable. For example, the range of unsigned integer is 0 to
65535. In this type, negative values and values greater than 65535 are compatible.
unsigned int x = 65536;
The value assigned is greater by 1 than the range. Here, the compiler starts again from beginning after
reaching the end of the range and the value 1 is assigned to x.
19. List the name of type modifiers.
Ans:  The keywords signed, unsigned, short and long are type modifiers. A type modifier
changes the meaning of basic data type and produces a new data type. Each of these type modifiers
M02_ITL-ESL4791_02_SE_C02.indd 18 12/22/2012 4:59:42 PM
The C Declarations II-19
is applicable to the basic data type int. The modifiers signed and unsigned are also applicable
to the type char. The long type modifier can be applicable to double type.
Example:
long l; /*int data type is applied*/
int s; /*signed is default*/
unsigned long int x; /*int keyword is optional*/
20.What is dynamic initialization?
Ans: The initialization of variable at run time is called dynamic initialization. Dynamic refers to
the process during execution. In C, initialization can be done at any place in the program; however, the
declaration should be done at the declaration part only.
21.Write a program that supports dynamic initialization.
Ans:
void main()
{
int r=2;
float perimeter=2*3.14*r;
float area=3.14*r*r;
clrscr();
printf(" Perimeter=%g Area=%g ",perimeter,area);
getche();
}
OUTPUT:
Perimeter = 12.56
Area = 12.56
Explanation: Variables are initialized at run time.
Multiple-choice Questions
1. A character variable can store only .
(a) 1 character (b) 20 characters (c) 254 characters (d) None of the above
2. A ‘C’ variable should not start with .
(a) A number (b) An alphabet (c) A character (d) None of the above
3. A short integer variable occupies memory .
(a) 2 byes (b) 4 bytes (c) 1 byte (d) 8 bytes
4. ‘C’ keywords are reserved words by .
(a) A compiler (b) An interpreter (c) Header file (d) Both (b) and (c)
5. The declaration of ‘C’ variable can be done .
(a) Anywhere in the program (b) In declaration part
(c) In executable part (d) At the end of program
M02_ITL-ESL4791_02_SE_C02.indd 19 12/22/2012 4:59:42 PM
II-20 Programming Concepts
6. In ‘C’ one statement can declare .
(a) Only one variables (b) Two variables
(c) Ten variables (d) Any number of variables
7. The word ‘int is a .
(a) Keyword (b) Password
(c) Header file (d) None of the above
8. The variables are initialized using .
(a) Greater than (>) (b) Equal to (=)
(c) Twice equal to (==) (d) An increment operator (++)
9. An unsigned integer variable contains values .
(a) Greater or equal to zero (b) Less than zero
(c) Only zeros (d) Both (a) and (b)
10. The keyword ‘const keeps the value of a variable .
(a) Constant (b) Mutable
(c) Variant (d) None of the above
11. Identifiers are .
(a) User-defined names (b) Reserved keywords
(c) ‘C’ statements (d) None of the above
12. In ‘C’, every variable has .
(a) A type (b) A name
(c) A value (d) A size
(e) All of the above
13. The range of character data type is .
(a) –128 to 127 (b) 0 to 255
(c) 0 to 32767 (d) None of the above
14. An unsigned integer variable occupies memory .
(a) 2 byes (b) 4 bytes
(c) 1 byte (d) 8 bytes
15. In ‘C’, double variable needs memory of size .
(a) 4 bytes (b) 2 bytes
(c) 10 bytes (d) All of the above
16. ‘C’, main() is a .
(a) User-defined function (b) Library function
(c) String function (d) Any number of variables
17. The word ‘continue is a .
(a) Keyword (b) Password
(c) Header file (d) None of the above
18. The volatile variables are those variables that remain/can be .
(a) Constant (b) Changed at any time
(c) Both of the above (d) None of the above
M02_ITL-ESL4791_02_SE_C02.indd 20 12/22/2012 4:59:42 PM
The C Declarations II-21
19. In C, the statements following main() are enclosed within .
(a) { } (b) ( ) (c) < > (d) None of the above
20. In ‘C’, the maximum value of unsigned character is .
(a) 255 (b) 127
(c) 65535 (d) None of the above
21. The range of long signed integer is .
(a) –2147483648 to 2147483647 (b) 0 to 255
(c) 0 to 4294967295 (d) None of the above
22. In C, ‘sizeof is a/an .
(a) Variable (b) Operator
(c) Keyword (d) None of the above
23. Which is the incorrect variable name ?
(a) else (b) name (c) age (d) cha_r
24. How many keywords are there in ANSI C ?
(a) 32 (b) 33 (c) 42 (d) 15
25. Integer constants in C can be .
(a) Positive (b) Negative
(c) Positive or negative (d) None of the above
26. Which of the following statement is wrong?
(a) 5+5 = a; (b) ss = 12.25; (c) st = ’m’ * ’b’; (d) is =’A+10;
27. In C, the first letter of the variable should be .
(a) Integer (b) An alphabet or underscore
(c) Floating number (d) None of the above
28. What is the output of the following program?
#include <stdio.h>
#include <conio.h>
void main()
{
unsigned long v=-1;
clrscr();
printf(" %lu",v);
}
(a) 4294967295 (b) 0
(c) –1 (d) None of the above
29. What would be the values of variables c and u?
#include <stdio.h>
#include <conio.h>
void main()
M02_ITL-ESL4791_02_SE_C02.indd 21 12/22/2012 4:59:42 PM
II-22 Programming Concepts
{
char c=-127;
unsigned char u=-127;
clrscr();
printf(" c=%d u= %d",c,u);
}
(a) c = 127 u = 127 (b) c = −127 u = 127
(c) c = 127 u = 128 (d) None of the above
30. The error message ‘Cannot modify a constant object’ is displayed when user .
(a) Attempts to modify the constant variable
(b) Attempts to use the variable in expressions
(c) Attempts assign value of constant variable to another variable
31. The following program will display the warning message .
int x=2,y=2;
printf("x=%d",x);
(a) ‘y’ is assigned a value which is never used in function main()
(b) Expression syntax in main
(c) Possible use of ‘y’ before definition in function main
32. The following program will display the warning message .
int x,y;
printf("x=%d",x);
(a) ‘y’ is assigned a value which is never used in function main()
(b) Expression syntax in main
(c) Possible use of ‘x’ before definition in function main
33. Each header files extension in C program is done with .
(a) .h (b) .p
(c) .c (d) None of the above three
34. The format string for char data type is .
(a) %c (b) %d
(c) %u (d) %f
35. The format string for int is .
(a) %c (b) %d
(c) %u (d) %f
36. The format string for long float is .
(a) %c (b) %d
(c) %u (d) %lf
37. The format string for float data type .
(a) %f (b) %d
(c) %u (d) %lf
M02_ITL-ESL4791_02_SE_C02.indd 22 12/22/2012 4:59:42 PM
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset