0% found this document useful (0 votes)
796 views10 pages

Which of The Following Is Not A Compound Assignment Operator?

The document contains 20 coding questions related to C programming concepts like operators, precedence, increment/decrement operators, logical operators etc. For each question there is a code snippet followed by 4 multiple choice answers, with the correct answer highlighted. Some key questions cover operator precedence, pre/post increment, logical operators, and the difference between expressions with && and || operators.

Uploaded by

Shweta Shah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
796 views10 pages

Which of The Following Is Not A Compound Assignment Operator?

The document contains 20 coding questions related to C programming concepts like operators, precedence, increment/decrement operators, logical operators etc. For each question there is a code snippet followed by 4 multiple choice answers, with the correct answer highlighted. Some key questions cover operator precedence, pre/post increment, logical operators, and the difference between expressions with && and || operators.

Uploaded by

Shweta Shah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

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

a) /=
b) +=
c) %=
d) == 

ANSWER: d) ==

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

Y = 5, X=0;
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

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


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

#include <stdio.h>

void main()

printf("value is = %d",(10++));

a) 10
b) 11
c) 0
d) ERROR

Correct Answer - 4
Error : L-value required
++/-- operator works on variables only.

#include <stdio.h>

void main()

const char var='A';

++var;

printf("%c",var);

}
1. B
2. A
3. ERROR
4. 66

Correct Answer - 3
Error : increment of read-only variable 'var'.
++/-- operator works on variables only, we cannot change the value of a const.

#include <stdio.h>

void main()

{  

    int x=10;

    x+=(x++)+(++x)+x;

    printf("%d",x);

1. 44
2. 45
3. 46
4. 47

Correct Answer - 2
45
1) expand the expression : x=x+(x++)+(++x)+x;
2) due to pre increment ++x , x will be 11 for this expression.
3) after executing expression x will be 44.
4) finally x will be 45 due to post increment (x++).
Note: the output of pre and post increment based operators may not same on all the
compilers, in GCC Linux compiler output will be 46 and in TurboC output will be
45.

#include <stdio.h>

void main()

{  

    int a=10,b=2,x=0;

    x=a+b*a+10/2*a;
    printf("value is =%d",x);

1. valie is =1250
2. value is =80
3. value is =125
4. ERROR

Correct Answer - 2
value is =80

#include <stdio.h>

void main()

{  

    int x=(20 || 40 ) && (10);

    printf("x= %d",x);

1. x= 60
2. x= 70
3. x= 0
4. x= 1

Correct Answer - 4
x=1
1)(20 || 40) .... both are non zero values, will return 1.
2)(1) && 10 .... both are non zero values, hence output will be 1.

#include <stdio.h>
void main()
{
    int x;
    x= (printf("AA")||printf("BB"));
    printf("%d",x);
    printf("\n");
 
    x= (printf("AA")&&printf("BB"));
    printf("%d",x);
}
1. AABB1
AABB1
2. 1
1
3. AABB1
AA1
4. AA1
AABB1

Correct Answer - 4
AA1
AABB1
1)printf() return total number of characters, printf("AA") will return 2 hence expression is true
second expression printf("BB") will not execute.
2)in this statement both expressions will execute.

You might also like