C Operator Q&A

C operators Q & A


Ques 1. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int m,n,p;

    m=(1,2,3);
    p =1,2,3;

    printf("i = %d\n",m+p);
    return 0;
}

options:
A. 4
B. 2
C. 6
D. compile time error



Ques 2. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int x=2,y=2,z=1,k=4, h=3;

    z+=x==y=k==h;

    printf("Hello world! %d\n",z);
    return 0;
}

options:
A. 2
B. compiler error lvalue required 
C. 3
D. 4


Ques 3. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int x=2,y=2,z=1,k=4, h=3;

    z+=x==(y=k==h);

    printf("%d\n",z);
    return 0;
}

options:
A. 2
B. 0
C. 1
D. compiler error


Ques 4. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int xyz=2,3,4;

    xyz+=5;
    printf("%d\n",xyz);
    return 0;
}

options:
A. 9
B. 8
C. 7
D. compiler error


Ques 5. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int xyz=(2,3,4);

    xyz+=5;
    printf("%d\n",xyz);
    return 0;
}

options:
A. 7
B. 9
C. 8
D. compiler error


Ques 6. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int mn=5;
    ++mn++;

    printf("%d\n",mn);
    return 0;
}

options:
A. 6
B. compiler error
C. 7
D. 8


Ques 7. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int xyz;
    xyz=2,3,4;

    xyz+=5;
    printf("%d\n",xyz);
    return 0;
}

options:
A. 9
B. 8
C. 7
D. compiler error


Ques 8. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int mn=5;
    ++mn;

    printf("%d\n",mn++);
    return 0;
}

options:
A. 8
B. 7
C. 6
D. compiler error


Ques 9. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int mn=5,y,z,s;
    mn = (y=mn++) + (z=mn++) + (s=++mn);

    printf("%d\n",mn++);
    return 0;
}

options:
A. 19
B. 21
C. 22
D. compiler error


Ques 10. what is the output for the below code?
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int mn=5;
    mn = mn++ + mn-- + --mn;

    printf("%d\n",mn++);
    return 0;
}

options:
A. 16 
B. 14
C. 15
D. compiler error



Ques 11. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int mn=5, y=3;

    printf("%d\n",mn>y? 22:44);
    return 0;
}
options:
A. 44
B. 22
C. 5
D. 3



Ques 12. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int fun(int *m, int *n)
{
    int sub = *m-*n;
    *m=*n;
    return *m+*n;

}
int main()
{
    int *a,*b;
    int x=22,y=3;

    a=&x; b=&y;

    printf("%d\n",fun(a,b));
    return 0;
}

options:
A. 6
B. compiler error
C. 22
D. 8



Ques 13. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int fun(int *m, int *n)
{
    int sub = *m-*n;
    *m=*n;
    return *m+*n;

}
int main()
{
    int *a,*b;
    a=(int *)malloc(4);
    b=a;

    *a=3; *b=5;

    printf("%d\n",fun(a,b));
    return 0;
}
options:
A. 8
B. 10
C. 13
D. compiler error


Ques 14. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

void fun(int **m, int **n)
{
    int t = *m;
    *m=*n;
    *n=t;
}
int main()
{
    int *a,*b;
    a=(int *)malloc(4);
    b=a;

    *a=3; *b=5;
    fun(&a,&b);

    printf("%d %d\n",*a, *b);
    return 0;
}

options:
A. 3 5
B. 5 3
C. 5 5
D. compiler error


Ques 15. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

void fun(int **m, int **n)
{
    int t = *m;
    *m=*n;
    *n=t;
}
int main()
{
    int *a,*b;
    a=(int *)malloc(sizeof(int)*2);
    b=a;

    *a=3; *b=5;
    *a = *b && fun(&a,&b);

    printf("%d %d\n",*a, *b);
    return 0;
}

options:
A. compiler error
B. 1 5
C. 5 5
D. 5 1


Ques 16. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int fun(int **m, int **n)
{
    int t = *m;
    *m=*n;
    *n=t;
    return *m=*n;
}

int main()
{
    int *a,*b;
    a=(int *)malloc(sizeof(int)*2);
    b=a;

    *a=3; *b=5;
    *a = *b && fun(&a,&b);

    printf("%d %d\n",*a, *b);
    return 0;
}

options:
A. compiler error
B. 1 1
C. 5 5
D. 3 3 


Ques 17. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b;

    a=3; b=5;
    b = sizeof( a *= b+5);

    printf("%d %d\n",a, b);
    return 0;
}

options:
A. 3 5
B. 3 20
C. 3 4
D. compiler error

Ques 18. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c, d;
    a = 5; b=4; d=7;

    c=a & b | d;

    printf("%d \n", c);
    return 0;
}

options:
A. 7
B. 5
C. 4
D. compiler error



Ques 19. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c, d, e=6;
    a = 5; b=4; d=7;

    c=a & b | d ^ e;

    printf("%d \n", c);
    return 0;
}

options:
A. 4
B. 7
C. 5
D. compiler error

Ques 20. what is the output for the below code?

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c, d, e=2;
    a = 5; b=4; d=7;

    c=a >> b | d << e;

    printf("%d \n", c);
    return 0;
}

options:
A. 22
B. 28
C. 7
D. compiler error




Answers

1. A 2. B 3. C 4. D 5. B 6. B 7. C 8. C 9. A 10. C 11. B 12. A 13. B 14. C 15. A 16. B 17. C 18. A 19. C 20. B