C Operators MCQs

C Operators MCQs


1. Which of the following is not a compound assignment operator?

a) /=
b) +=
c) %=
d) ==
View Answer / Hide Answer

ANSWER: d) ==




2. What will be the output of the following code snippet?

Y = 5;
if (! Y > 10)
X = Y + 3;
else
X = Y + 10;

printf(“ X = %d Y = %d”, X, Y);

a) The program will print X = 15 Y = 5
b) The program will print X = 15 Y = 0
c) The program will print X = 8 Y = 5
d) The program will print X = 3 Y = 0
View Answer / Hide Answer

ANSWER: a) The program will print X = 15 Y = 5




3. Which of the following statement is correct about the code snippet given below?

num = 5;
printf( “%d”, ++num++ );

a) The code will print 5
b) The code will print 6
c) The code will result in L – value required
d) The code will result in R – value required
View Answer / Hide Answer

ANSWER: c) The code will result in L – value required




4. Which of the following statement is correct about the code snippet given below?

#include < stdio.h>
int main()
{
float z = 12.35, c = 10;
if( ++z%10 -z)
c += z;
else
c - = z;
printf( “%f %f”, z, c);
return 0;
}

a) The program will result in compile time error
b) The program will print 12.35 22.35
c) The program will print 13.35 22.35
d) The program will print 1.35 11.35
View Answer / Hide Answer

ANSWER: a) The program will result in compile time error




5. Which of the following statement is correct about the code snippet given below?

#include < stdio.h>
int main()
{
int n = 12, k;
printf(“%d”, (k = sizeof( n + 12.0))++);
return 0;
}

a) The code will print 17
b) The code will print 5
c) The code will result compile time error
d) The code will print 4
View Answer / Hide Answer

ANSWER: c) The code will result compile time error




6. Which is executed quickly?

a) ++p
b) P++
c) Both
d) P+1
View Answer / Hide Answer

ANSWER: c) Both




7. What is the value of X in the sample code given below?

double X; X = ( 2 + 3) * 2 + 3;

a) 10
b) 13
c) 25
d) 28
View Answer / Hide Answer

ANSWER: b) 13




8. What value will be stored in z if the following code is executed?

main()
{
int x = 5; y = -10, z;
int a = 4, b = 2;
z = x+++++y * b/a;
}

a) -2
b) 0
c) 1
d) 2
View Answer / Hide Answer

ANSWER: c) 1




9. What is the output of the following program?

#include < stdio.h>
int main()
{
int max =123, min = 10, *maxptr = &max, *minptr = &min;
int **nptr = &minptr, **mptr = &maxptr;
*maxptr = ++*mptr % **nptr;
max - = ( *minptr -**nptr && *maxptr || *minptr);
printf( “ %d %d”, ++**mptr, *minptr);
return 0;
}

a) 4 10
b) 3 11
c) 3 10
d) 4 11
View Answer / Hide Answer

ANSWER: a) 4 10




10. What will be the output of the following program?

#include < stdio.h>
int main()
{
int num = 0, z = 3;
if ( ! (num <= 0) || ++z )
printf( “%d %d ”, ++num + z++, ++z );
else
printf( “%d %d”, - -num + z- -, - - z);
return 0;
}

a) – 2 1
b) 6 5
c) 4 5
d) 5 5
View Answer / Hide Answer

ANSWER: b) 6 5




11. Which of the following statement is correct about the code snippet given below?

#include < stdio.h>

int main()
{
int a = 10, b = 2, c;
a = !( c = c == c) && ++b;
c += ( a + b- -);
printf( “ %d %d %d”, b, c, a);
return 0;
}

a) The program will print the output 1 3 0
b) The program will print the output 0 1 3
c) The program will results in expression syntax error
d) The program will print the output 0 3 1
View Answer / Hide Answer

ANSWER: a) The program will print the output 1 3 0




12. Which of the following is the better approach to do the operation i = i * 16?

a) Multiply I by 16 and keep it
b) Shift left by 4 bit
c) Add I 16 times
d) Shift right by 4 bit
View Answer / Hide Answer

ANSWER: b) Shift left by 4 bit




13. For the following statement find the values generated for p and q?

int p = 0, q = 1;
p = q++;
p = ++q;
p = q--;
p = --q;

Value of p & q are

a) 1 1
b) 0 0
c) 3 2
d) 1 2
View Answer / Hide Answer

ANSWER: a) 1 1




14. What is the value of the following expression?

i = 1;
i = ( I< <= 1 % 2)

a) 2
b) 1
c) 0
d) Syntax error
View Answer / Hide Answer

ANSWER: a) 2




15. What is the correct and fully portable way to obtain the most significant byte of an unsigned integer x?

a) x & 0xFF00
b) x > > 24
c) x > > ( CHAR_BIT * (sizeof(int) - 3))
d) x > > ( CHAR_BIT * (sizeof(int) - 1))
View Answer / Hide Answer

ANSWER: d) x > > ( CHAR_BIT * (sizeof(int) - 1))




16. Expression x % y is equivalent to____?

a) (x – (x/y))
b) (x – (x/y) * y)
c) (y – (x/y))
d) (y – (x/y) * y)
View Answer / Hide Answer

ANSWER: b) (x – (x/y) * y)




17. What is the value of x after executing the following statement?

int x = 011 | 0x10;

a) 13
b) 19
c) 25
d) 27
View Answer / Hide Answer

ANSWER: c) 25




18. What is the value of the following expression?

i = 1;
i < < 1 % 2;

a) 2
b) -2
c) 1
d) 0
View Answer / Hide Answer

ANSWER: a) 2




19. p++ executes faster than p + 1 since

a) P uses registers
b) Single machine instruction required for p++
c) Option a and b
d) None
View Answer / Hide Answer

ANSWER: b) Single machine instruction required for p++



Post your comment