C Programming - 2
Advanced C programming quiz testing operators, loops, pointers, structs, functions, and preprocessor directives with focus on output prediction and language nuances.
Questions
What is the value of variable POLYGON?
main()
{
int POLYGON, L, B; L=B =2; POLYGON = (L==B) ? 1 : 0;
}
- 0
- 1
- 2
- None of the above
If ASCII value of 'x' is 120. What is the value of i = ('x' - 'w')/3?
- 1
- 2
- 0
- 4
What will be the value of sum after the following program is executed?
main() {
int sum, index; sum = 1; index = 9;
do {
index = index - 1; sum = 2*sum; } while(index >9);
- 1
- 2
- 9
- 0.5
How many times will the following loop be executed if the input data item is 01234?
while( c = getchar() ! = 0) {
- Infinitely
- Never
- Once
- Five
What is the final value of digit?
main()
{
int digit; for(digit = 0 ; digit <=9; ++digit)
printf(“%d ”,digit);
digit = 2*digit; --digit; }
- 19
- -1
- 17
- 16
The library function sqrt operates on a double precision argument. If i is an integer variable, which one of the following calls would correctly compute sqrt(i)?
- sqrt((double)i)
- (double) sqrt(i)
- (double)(sqrt(i))
- sqrt(i)
If a = 0x6db7 and b = 0xa726, what is the value of a ^ b?
- 0x58d9
- 0xca91
- 0xceb7
- 0x2526
If a = 0x6db7 and b = 0xa726, then what is the value of a & b?
- 0xca91
- 0x6db7
- 0xab92
- 0x2526
What would be the output of the follwing program?
sum = 0;
for(i=1;i<10;i++)
if(i%2==0) sum +=i;
printf(“%d”, sum);
- 45
- 0
- 40
- 30
If a = -11 & b = -3, what is the value of a % b?
- -3
- -2
- 2
- 3
Suppose i =7, f = 5.5 and c = 'W', what is the value of the given expression?
(c ! = 'p' || i+f <=10)
- 1
- 0
- -1
- Not defined
Suppose i, j and k are integer variables with values 1, 2, 3 respectively, what is the value of the following expression?!((j+k) > (i+5))
- 5
- 0
- 1
- 6
The ''puts(argv[0]);'' prints
- the name of source file
- Argv
- the no. of command line arguments
- name of executable file
If n = 10, then the statement arr[++n] = n++ assigns
- 10 to arr[12]
- 4 to arr[12]
- 4 to arr[11]
- compiler dependent
Consider the following program fragment.
main()
{
int a,b,c; b=2 ; a= 2*(b++); c = 2*(++b); }
Which one of the following is correct?
- a = 4, c = 6
- a = 3, c = 8
- b = 3, c = 6
- a = 4, c = 8
What will be the value of i?
int i = 1;
i = i +2*i ++;
printf(“%d”,i);
- 4
- 1
- 3
- 2
The expression ''4 + 6/3 * 2 - 2 + 7 %3'' is equal to
- 3
- 4
- 6
- 7
What will be the value of y in the following program fragment?
int y = 10;
If(y++ >9 && y++! = 10 && y++>10)
- 10
- 11
- 12
- 13
printf( “ab”, “cd”, “ef”); prints
- ab
- abcdef
- abcdef, followed by garbage
- none of above
The following program fragment prints
int a= 5 , b=2;
printf(“%d” , a+++++b);
- 7
- 8
- 9
- none of above
The following program results in
main()
{
printf(“%u”, main);
}
- printing of a garbage number
- an execution error
- printing of starting address of the function main
- an infinite loop
Consider the following declaration.
int a = 5, b = &a;
printf(“%d”, ab);The above program prints
- 25
- garbage
- 5 x address of b
- error message
If 7 bits are used to store a character, the percentage reduction of needed storage will be
- 22.5
- 2.5
- 8
- 12.5
Consider the declaration.
int a = 5, *b = &a;
printf(“%d”, a**b); prints
- 25
- garbage
- 0
- error message
The following program prints
main()
{
int i = 5; i = (++i) / (i ++);
printf(“%d”,i);
}
- 2
- 5
- 1
- 6
Directions: Answer the following question, based on the following declaration.
struct {
char city[10];
char street[20];
int pincode;
} addr;
struct {
char name[20];
int sex ;
addr locate;
} criminal,*kd = &criminal;
The third character in the criminal name can be accessed by
- criminal.name[2]
- kd->name[2]
- (*kd).name[2]
- either (2) or (3), but not by (1)
The statement fseek(fp,0L,0) means
- fp is a file pointer
- position the read-write-head at the start of the file
- position the read-write-head at the end of the file
- erase the contents of the file
Directions: Answer the following question based on the following declaration.
struct {
char city[10];
char street[20];
int pincode;
} addr;
struct {
char name[20];
int sex ;
addr locate;
} criminal,*kd = &criminal;
*(kd ->name + 2) can be used instead of
- *( criminal.name + 2)
- kd -> (name + 2)
- *((*kd).name + 2)
- either (2) or (3), but not by (1)
The following declaration means
int x : 4;
- x is a 4-digit integer
- x cannot be greater than a 4 digit integer
- x is a 4-bit integer
- none of above
The most significant bit will be lost in
- <<
- complementation
- >>
- none of above
The declaration
enum cities { bethlehem, jericho, nazareth = 1, jerusalem }
assign(s) the value 1 to
- bethlehem
- nazareth
- bethlehem and nazareth
- jericho and nazareth
The output of the following program will be
main()
{ int a = 1, b=2, c=3;
printf(“%d”, a+=(a+=3,5,a)); }
- 8
- 12
- 9
- 6
Directions: Answer the following question based on the following declaration.
struct {
char city[10];
char street[20];
int pincode;
} addr;
struct {
char name[20];
int sex ;
addr locate;
} criminal,*kd = &criminal;
The pincode can be accessed by
- criminal.locate.pincode
- criminal.pincode
- kd->locate.pincode
- kd.locate ->pincode
If one wants to retain certain bits and set the rest from a given bit pattern, the correct masking operation is
- OR
- AND
- Exclusive OR
- Complementation
The following statements find the
define hypotenuse(a, b) sqrt( aa + bb);
the macro call hypotenuse (a+2,b+3);
- hypotenuse of a triangle with sides, a+2 and b+3.
- the square root of 3a + 4b + 5
- the square root of (a+2) 2 + (b+3) 2
- none of these
If the word size is 16 bit, ~0xc5 will be
- 0x3a
- 0xff3a
- 0x5c
- none of above
Directions: Answer the following question, based on the following declaration
struct {
char city[10];
char street[20];
int pincode;
} addr;
struct {
char name[20];
int sex ;
addr locate;
} criminal,*kd = &criminal;
The 'sex' can be accessed by
- criminal.sex.
- kd -> sex.
- (*kd).sex.
- either (1) or (3) but not by (2)
The program
main()
{
float b = 0.7; printf(“%d, %f”,b,b);
}
prints
- a garbage value 0.7
- 0 ,0.0
- 7, 0.7
- an error message
In a certain machine, the sum of an integer and its 1's complement is 220-1. What is the size of (int), in bits?
- 16
- 32
- Unpredictable
- None of above
Lint is
- a tool for analyzing a C program
- an interactive debugger
- a C interpreter
- a C compiler
What is the output of the following 'C' program?
main()
{
printf(“ %x”,-1 >>4);
}
- ffff
- 0fff
- 0000
- fff0
The statement printf (“%d”, sizeof(“”)); prints
- an error message
- 0
- garbage
- 1
If y is of integer type, the expressions 3*(y-8)/9 and (y-8)/9*3 yield the same result if
- y is an even number
- y is an odd number
- (y-8) is a multiple of 9
- (y-8) is a multiple of 3
What header file should be included if you are to develop a function that can accept variable no. of arguments?
- vararg.h
- stdlib.h
- stdio.h
- stdarg.h
In C language, x = x-y+1; means
- x = x-y+1
- x = -x-y-1
- x = -x + y +1
- x = x-y-1
What does the statement printf(“%d”,10?0?5:11:12); print?
- 10
- 0
- 12
- 11
The rule for implicit type conversion in 'C' is
- int < unsigned < float < double
- unsigned < int < float < double
- int< unsigned < double < float
- unsigned < int < double < float
What does the following C statement print?
print(“%d”, ++5);
- 5
- 6
- 7
- An error message
What is the output of following 'C' fragment?
For(i=1,j=10;i<6;++i,--j)
printf(“%d%d”,i,j);
- 1 10 2 9 3 8 4 7 5 6
- 1 2 3 4 5 10 9 8 7 6
- 1 1 1 1 1 9 9 9 9 9
- None of above
Recursive functions are executed in a
- last in first out order
- first in first out order
- parallel fashion
- any one of the above