C MCQ Set-17 : Multiple Choice Questions in C Set-17

Set-26 C MCQ

1. Assuming, integer is 2 byte, What will be the output of the program?

#include<stdio.h>
int main()
{
printf(“%x\n”, -2<<2);
return 0;
}
A. ffff
B. 0
C. fff8
D. Error

Answer : C


  1. What will be the output of the program?

#include<stdio.h>
int main()
{
int x=12, y=7, z;
z = x!=4 || y == 2;
printf(“z=%d\n”, z);
return 0;
}

A. z=0
B. z=1
C. z=4
D. z=2

Answer : B


  1. What will be the output of the program?

#include<stdio.h>
int main()
{
int i=4, j=-1, k=0, w, x, y, z;
w = i || j || k;
x = i && j && k;
y = i || j &&k;
z = i && j || k;
printf(“%d, %d, %d, %d\n”, w, x, y, z);
return 0;
}
A. 1, 1, 1, 1
B. 1, 1, 0, 1
C. 1, 0, 0, 1
D. 1, 0, 1, 1

Answer : D

  1. What will be the output of the program?

#include<stdio.h>
int reverse(int);

int main()
{
int no=5;
reverse(no);
return 0;
}
int reverse(int no)
{
if(no == 0)
return 0;
else
printf(“%d,”, no);
reverse (no–);
}

A. Print 5, 4, 3, 2, 1
B. Print 1, 2, 3, 4, 5
C. Print 5, 4, 3, 2, 1, 0
D. Infinite loop

Answer : C


  1. What will be the output of the program?

#include<stdio.h>
int main()
{
void fun(char*);
char a[100];
a[0] = ‘A’; a[1] = ‘B’;
a[2] = ‘C’; a[3] = ‘D’;
fun(&a[0]);
return 0;
}
void fun(char *a)
{
a++;
printf(“%c”, *a);
a++;
printf(“%c”, *a);
}

A. AB
B. BC
C. CD
D. No output

Answer : B


  1. What will be the output of the program?

#include<stdio.h>
int main()
{
int fun(int);
int i = fun(10);
printf(“%d\n”, –i);
return 0;
}
int fun(int i)
{
return (i++);
}

A. 9
B. 10
C. 11
D. 8

Answer : A
C MCQ Set-17 Explanation


  1. What will be the output of the program?

#include<stdio.h>
int check (int, int);

int main()
{
int c;
c = check(10, 20);
printf(“c=%d\n”, c);
return 0;
}
int check(int i, int j)
{
int *p, *q;
p=&i;
q=&j;
i>=45 ? return(p): return(q);
}

A. Print 10
B. Print 20
C. Print 1
D. Compile error

Answer : D


  1. What will be the output of the following C code?

    #include<stdio.h>
    int main ()
    {
    char *s= “hello”;
    char *p = s;
    printf(“%s ,%s”, p+1, s+2);
    }

    a) Run time error
    b) hello,llo
    c) ello,llo
    d) e,l

Answer : C
C MCQ Set-17 Explanation


  1. What will be the output of the following C code?

    #include<stdio.h>
    int main( )
    {
    int ary[4] = {1, 2, 3, 4};
    int *p = ary + 3;
    printf(“%d\n”, p[-2]);
    }
    a) 1
    b) 2
    c) Compile time error
    d) Some garbage value

Answer : B


  1. What will be the output of the following C code?

    #include<stdio.h>
    int main( )
    {
    int *p = (int *)2;
    int *q = (int *)3;
    printf(“%d”, p + q);
    }
    a) 2
    b) 3
    c) 5
    d) Compile time error

Answer : D


Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *