MCQ Questions in c


C programming MCQ questions and answers with explanation for written test exam and interview

1
#include<stdio.h>

int main(){

printf("%d",sizeof(3.8));

return 0;

}

Which of the following is true?

(a)4

(b)8

(c)10

(d)Compiler error

(e)None of these
Answer
Explanation:
Answer: (b)
3.8f is float constant, 3.8 is double constant and 3.8L is long double constant .Here are finding size of double constantan which is 8

2
#include<stdio.h>

int main(){

char *str1="powla";

char *str2="er";

printf("%s\b\b%s",str1,str2);

return 0;

}

Which of the following is true?

(a)powlaer

(b)pow

(c)power

(d)Compiler error

(e)None of these
Answer
Explanation:
Answer: (c)
\b escape sequence back the cursor one position left .We are using two /b so after writing str1 cursor is at the position of l of powal .So when it write er it will override the la so output will be power.

3
#include<stdio.h>

int main(){

int a=270;

char *p;

p=(char *)&a;

printf("%d",*p);

return 0;

}

Which of the following is true?

(a)270

(b)address of variable a

(c)16

(d)Compiler error

(e)None of these
Answer
Explanation:
Answer: (c)

4
What is missing statement of in the following program?

#include<stdio.h>

int main(){

int sort(int,int);

int I;

i=sort(5,6);

return 0;

}

int sort(int a,int b){

int c;

c=a;

a=b;

b=c;

return a;

}
Answer
Explanation:
Function sort returning a value but we are not using return value so there is wastage of two byte memory. So missing statement is, there should statement which uses the return value.

5
Write following in term of if and else:

#include<stdio.h>

int main(){

int a=1,b=2,c=3;

if(a==5&&b==6&&c==7)

printf("india");

else

printf("pak");

return 0;

}
Answer
Explanation:
#include<stdio.h>

int main(){

int a=1,b=2,c=3;

if(a==1){

if(b==2){

if(c==3){

printf("india");

}

else{

printf("pak");

}

}

else{

printf("pak");

}

}

else{

printf("pak");

}

}

6
Draw memory representation of

struct xxx{

char a;

int b;

char c;

};
Answer
Explanation:
Why we cannot use column alias in where clause but we can use select clause in sql server?

7
Write the following program in term of switch and case?

#include<stdio.h>

int main(){

int a=3;

if(x>2){

printf(“INDIA IS BEST”);

}

else{

printf(“PAK IS BEST”);

}

return 0;

}
Answer
Explanation:
if condition always return two value.

1 if condition is true.

0 if condition is false.

So program is

#include<stdio.h>

int main(){

int x=3;

switch(x>2){

case 0:printf("India is best");

break;

case 1:printf("Pak is best");

}

}

8
#include<stdio.h>

int main(){

int far *a=(int far*)0x50000011;

int far *b=(int far*)0x50010001;

int huge *c=(int huge*)0x50000011;

int huge *d=(int huge*)0x50010001;

if(a==b)

printf("I know C");

else

printf("I don't know C");

if(c==d)

printf("\nI know C");

else

printf("\nI don't know C");

return 0;

}

Which of the following is true?

(a)I know C

   I Know C

(b)I know C

   I don’t know C

(c)I don’t know C

   I know C

(d)Compiler error

(e)None of these
Answer
Explanation:
Answer: (c)
Far pointers always compare its whole far address. Since both or not equal so first output is: I don’t know C

Huge pointer always compare its physical address both c and d are representing same physical address so a and b are equal.

9
#include<stdio.h>

#define power(a) #a

int main(){

printf("%d",*power(432));

return 0;

}

Which of the following is true?

(a)*”432”

(b)432

(c)16

(d)32

(e)Compiler error
Answer
Explanation:
Answer: (c)
# is string zinging operator. It makes the string constant of any data. So 432 is converted into “432” by macro power .Now *”432” means first char which is 4.Since we are using %d so it will print ASCII value of char 4 i.e. 52

10
#include<stdio.h>

int main(){

int arr[]={1,2,3,4,5,6};

void xxx(int[5]);

xxx(arr);

return 0;

}

void xxx(int ch[5]){

printf("%d",-1[ch]);

}

Which of the following true?

(a)2

(b)-2

(c)3

(d)-3

(e)Compiler error
Answer
Explanation:
Answer: (b)
We are passing the array by xxx function. 1[ch] means *(ch+1) which is ch[1] =2.

11
What is difference between a, b, c and in following declaration?

#include<stdio.h>

#define xxx char *

typedef char * yyy;

int main(){

yyy a,b;

xxx c,d;

}
Answer
Explanation:
Both and b are char * type but c is char * type while d is char type.

12
Write a c program to find the HCF of any two numbers?
Answer
Explanation:
#include<stdio.h>

int main(){

int a,b,c;

scanf("%d%d%d",a,b,c);

while((c=a%b)!=0){

a=b;

b=c;

}

printf("%d",b);

}

13
#include<stdio.h>

int main(){

int a=5;{

a++;

}

printf("%d",a);

return 0;

}

Which of the following is true?

(a)5

(b)6

(c)7

(d)Compiler error

(e)None of these
Answer
Explanation:
Answer: (b)

14
#include<stdio.h>

int main(){

int a=5;{

int a=7;

a++;

printf(“%d”,a);

}

printf("%d",a);

return 0;

}

Which of the following is true?

(a)5 7

(b)5 8

(c)8 5

(d)7 5

(e)Compiler error
Answer
Explanation:
Answer: (c)
Scope of the auto variable is within {} if it is declared in {}.Also local variable has more priority than global variable.
If you have any queries or suggestions in above C MCQ or multiple choice questions of c, please suggest us.

3 comments:

Unknown said...

send answer of these questions.........

df said...

Answers for this............

Anonymous said...

More questions add please