C Programming - 2

Advanced C programming quiz testing operators, loops, pointers, structs, functions, and preprocessor directives with focus on output prediction and language nuances.

50 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

What is the value of variable POLYGON?
main()
{
int POLYGON, L, B; L=B =2; POLYGON = (L==B) ? 1 : 0;
}

  1. 0
  2. 1
  3. 2
  4. None of the above
Question 2 Multiple Choice (Single Answer)

If ASCII value of 'x' is 120. What is the value of i = ('x' - 'w')/3?

  1. 1
  2. 2
  3. 0
  4. 4
Question 3 Multiple Choice (Single Answer)

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. 1
  2. 2
  3. 9
  4. 0.5
Question 4 Multiple Choice (Single Answer)

How many times will the following loop be executed if the input data item is 01234?
while( c = getchar() ! = 0) {

  1. Infinitely
  2. Never
  3. Once
  4. Five
Question 5 Multiple Choice (Single Answer)

What is the final value of digit?
main()
{
int digit; for(digit = 0 ; digit <=9; ++digit)
printf(“%d ”,digit);
digit = 2*digit; --digit; }

  1. 19
  2. -1
  3. 17
  4. 16
Question 6 Multiple Choice (Single Answer)

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)?

  1. sqrt((double)i)
  2. (double) sqrt(i)
  3. (double)(sqrt(i))
  4. sqrt(i)
Question 7 Multiple Choice (Single Answer)

If a = 0x6db7 and b = 0xa726, what is the value of a ^ b?

  1. 0x58d9
  2. 0xca91
  3. 0xceb7
  4. 0x2526
Question 8 Multiple Choice (Single Answer)

If a = 0x6db7 and b = 0xa726, then what is the value of a & b?

  1. 0xca91
  2. 0x6db7
  3. 0xab92
  4. 0x2526
Question 9 Multiple Choice (Single Answer)

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);

  1. 45
  2. 0
  3. 40
  4. 30
Question 10 Multiple Choice (Single Answer)

If a = -11 & b = -3, what is the value of a % b?

  1. -3
  2. -2
  3. 2
  4. 3
Question 11 Multiple Choice (Single Answer)

Suppose i =7, f = 5.5 and c = 'W', what is the value of the given expression?
(c ! = 'p' || i+f <=10)

  1. 1
  2. 0
  3. -1
  4. Not defined
Question 12 Multiple Choice (Single Answer)

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))

  1. 5
  2. 0
  3. 1
  4. 6
Question 13 Multiple Choice (Single Answer)

The ''puts(argv[0]);'' prints

  1. the name of source file
  2. Argv
  3. the no. of command line arguments
  4. name of executable file
Question 14 Multiple Choice (Single Answer)

If n = 10, then the statement arr[++n] = n++ assigns

  1. 10 to arr[12]
  2. 4 to arr[12]
  3. 4 to arr[11]
  4. compiler dependent
Question 15 Multiple Choice (Single Answer)

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?

  1. a = 4, c = 6
  2. a = 3, c = 8
  3. b = 3, c = 6
  4. a = 4, c = 8
Question 16 Multiple Choice (Single Answer)

What will be the value of i?
int i = 1;
i = i +2*i ++;
printf(“%d”,i);

  1. 4
  2. 1
  3. 3
  4. 2
Question 17 Multiple Choice (Single Answer)

The expression ''4 + 6/3 * 2 - 2 + 7 %3'' is equal to

  1. 3
  2. 4
  3. 6
  4. 7
Question 18 Multiple Choice (Single Answer)

What will be the value of y in the following program fragment?
int y = 10;
If(y++ >9 && y++! = 10 && y++>10)

  1. 10
  2. 11
  3. 12
  4. 13
Question 19 Multiple Choice (Single Answer)

printf( “ab”, “cd”, “ef”); prints

  1. ab
  2. abcdef
  3. abcdef, followed by garbage
  4. none of above
Question 20 Multiple Choice (Single Answer)

The following program fragment prints
int a= 5 , b=2;
printf(“%d” , a+++++b);

  1. 7
  2. 8
  3. 9
  4. none of above
Question 21 Multiple Choice (Single Answer)

The following program results in
main()
{
printf(“%u”, main);

  1. printing of a garbage number
  2. an execution error
  3. printing of starting address of the function main
  4. an infinite loop
Question 22 Multiple Choice (Single Answer)

Consider the following declaration.
int a = 5, b = &a;
printf(“%d”, a
b);The above program prints

  1. 25
  2. garbage
  3. 5 x address of b
  4. error message
Question 23 Multiple Choice (Single Answer)

If 7 bits are used to store a character, the percentage reduction of needed storage will be

  1. 22.5
  2. 2.5
  3. 8
  4. 12.5
Question 24 Multiple Choice (Single Answer)

Consider the declaration.
int a = 5, *b = &a;
printf(“%d”, a**b); prints

  1. 25
  2. garbage
  3. 0
  4. error message
Question 25 Multiple Choice (Single Answer)

The following program prints
main()
{
int i = 5; i = (++i) / (i ++);
printf(“%d”,i);
}

  1. 2
  2. 5
  3. 1
  4. 6
Question 26 Multiple Choice (Single Answer)

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

  1. criminal.name[2]
  2. kd->name[2]
  3. (*kd).name[2]
  4. either (2) or (3), but not by (1)
Question 27 Multiple Choice (Single Answer)

The statement fseek(fp,0L,0) means

  1. fp is a file pointer
  2. position the read-write-head at the start of the file
  3. position the read-write-head at the end of the file
  4. erase the contents of the file
Question 28 Multiple Choice (Single Answer)

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

  1. *( criminal.name + 2)
  2. kd -> (name + 2)
  3. *((*kd).name + 2)
  4. either (2) or (3), but not by (1)
Question 29 Multiple Choice (Single Answer)

The following declaration means
int x : 4;

  1. x is a 4-digit integer
  2. x cannot be greater than a 4 digit integer
  3. x is a 4-bit integer
  4. none of above
Question 30 Multiple Choice (Single Answer)

The most significant bit will be lost in

  1. <<
  2. complementation
  3. >>
  4. none of above
Question 31 Multiple Choice (Single Answer)

The declaration
enum cities { bethlehem, jericho, nazareth = 1, jerusalem }
assign(s) the value 1 to

  1. bethlehem
  2. nazareth
  3. bethlehem and nazareth
  4. jericho and nazareth
Question 32 Multiple Choice (Single Answer)

The output of the following program will be
main()
{ int a = 1, b=2, c=3;
printf(“%d”, a+=(a+=3,5,a)); }

  1. 8
  2. 12
  3. 9
  4. 6
Question 33 Multiple Choice (Single Answer)

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

  1. criminal.locate.pincode
  2. criminal.pincode
  3. kd->locate.pincode
  4. kd.locate ->pincode
Question 34 Multiple Choice (Single Answer)

If one wants to retain certain bits and set the rest from a given bit pattern, the correct masking operation is

  1. OR
  2. AND
  3. Exclusive OR
  4. Complementation
Question 35 Multiple Choice (Single Answer)

The following statements find the

define hypotenuse(a, b) sqrt( aa + bb);

the macro call hypotenuse (a+2,b+3);

  1. hypotenuse of a triangle with sides, a+2 and b+3.
  2. the square root of 3a + 4b + 5
  3. the square root of (a+2) 2 + (b+3) 2
  4. none of these
Question 36 Multiple Choice (Single Answer)

If the word size is 16 bit, ~0xc5 will be

  1. 0x3a
  2. 0xff3a
  3. 0x5c
  4. none of above
Question 37 Multiple Choice (Single Answer)

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

  1. criminal.sex.
  2. kd -> sex.
  3. (*kd).sex.
  4. either (1) or (3) but not by (2)
Question 38 Multiple Choice (Single Answer)

The program
main()
{
float b = 0.7; printf(“%d, %f”,b,b);
}
prints

  1. a garbage value 0.7
  2. 0 ,0.0
  3. 7, 0.7
  4. an error message
Question 39 Multiple Choice (Single Answer)

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?

  1. 16
  2. 32
  3. Unpredictable
  4. None of above
Question 40 Multiple Choice (Single Answer)

Lint is

  1. a tool for analyzing a C program
  2. an interactive debugger
  3. a C interpreter
  4. a C compiler
Question 41 Multiple Choice (Single Answer)

What is the output of the following 'C' program?
main()
{
printf(“ %x”,-1 >>4);
}

  1. ffff
  2. 0fff
  3. 0000
  4. fff0
Question 42 Multiple Choice (Single Answer)

The statement printf (“%d”, sizeof(“”)); prints

  1. an error message
  2. 0
  3. garbage
  4. 1
Question 43 Multiple Choice (Single Answer)

If y is of integer type, the expressions 3*(y-8)/9 and (y-8)/9*3 yield the same result if

  1. y is an even number
  2. y is an odd number
  3. (y-8) is a multiple of 9
  4. (y-8) is a multiple of 3
Question 44 Multiple Choice (Single Answer)

What header file should be included if you are to develop a function that can accept variable no. of arguments?

  1. vararg.h
  2. stdlib.h
  3. stdio.h
  4. stdarg.h
Question 45 Multiple Choice (Single Answer)

In C language, x = x-y+1; means

  1. x = x-y+1
  2. x = -x-y-1
  3. x = -x + y +1
  4. x = x-y-1
Question 46 Multiple Choice (Single Answer)

What does the statement printf(“%d”,10?0?5:11:12); print?

  1. 10
  2. 0
  3. 12
  4. 11
Question 47 Multiple Choice (Single Answer)

The rule for implicit type conversion in 'C' is

  1. int < unsigned < float < double
  2. unsigned < int < float < double
  3. int< unsigned < double < float
  4. unsigned < int < double < float
Question 48 Multiple Choice (Single Answer)

What does the following C statement print?
print(“%d”, ++5);

  1. 5
  2. 6
  3. 7
  4. An error message
Question 49 Multiple Choice (Single Answer)

What is the output of following 'C' fragment?
For(i=1,j=10;i<6;++i,--j)
printf(“%d%d”,i,j);

  1. 1 10 2 9 3 8 4 7 5 6
  2. 1 2 3 4 5 10 9 8 7 6
  3. 1 1 1 1 1 9 9 9 9 9
  4. None of above
Question 50 Multiple Choice (Single Answer)

Recursive functions are executed in a

  1. last in first out order
  2. first in first out order
  3. parallel fashion
  4. any one of the above