C programming MCQ


1.
Turbo C 3.0 is based on
(A) DOS
(B) UNIX
(C) Windows
(D) LINUX
(E) None


Explanation:
**

2.
Turbo C 4.5 is based on
(A) DOS
(B) UNIX
(C) Windows
(D) LINUX
(E) None


Explanation:
**

3.

Find the output of following c code?
#include<stdio.h>
int main(){
int a=4,b=5;
printit(a, b);
}
printit(int b, int a){
printf("%d %d", a, b);
{
int a=0;
int b=1;
printf("%d %d", a, b);
}
return 0;
} 


(A) 4 5 0 1
(B) 5 4 0 1
(C) 5 4 5 4
(D) None of these
(E) Compilation error

Explanation:
**

4.

The contents of a file will be lost if it is opened in

(A) a mode
(B) a- mode
(C) w+ mode
(D) a+ mode
(E) r mode


Explanation:
**

5.

Find the output of following c code.
#include<stdio.h>
int main(){
int i=1,j=2,k=3;
if(i==1)
if(j==2)
if(k==3){
printf("ok");
break;
}
else
printf("continue");
printf("bye");
return 0;


(A) ok
(B) okbye
(C) Misplaced break
(D) None of these
(E) It will print nothing


Explanation:
**

6.

Find the output of following c code.

#include<stdio.h>
int main(){
printf("C\question\bank");
return 0;
}

(A) Cquestionbank
(B) cuestionank
(C) cuestioank
(D) cquestioank
(E) None of these.


Explanation:
**

7.

What will be output if you will execute following c code?

#include<stdio.h>
int main(){
    char c=+'A';
    printf("%d",c);
return 0;
}

(A) 65
(B) 130
(C) Garbage value
(D) 0
(E) Compilation error


Explanation:
**

8.

What will be output if you will execute following c code?

#include<stdio.h>
int main(){
    int num,a=5;
    num=+++a;
    printf("%d  %d",num,a);
return 0;

}

(A) 5 5
(B) 6 6
(C) 7 7
(D) 5 6
(E)
Compilation error


Explanation:
**

9.

What will be output if you will execute following c code?

#include<stdio.h>
int main(){
    int num,a=10;
    num=a+++ +++a;
    printf("%d  %d",num,a);
return 0;

}

(A)
20 10
(B) 21 12 
(C) 22 12
(D) 21 11 
(E) Compilation error


Explanation:
**

10.

What will be output if you will execute following c code?

#include<stdio.h>
int main(){
    int z;
    z=5,3,2;
    printf("%d",z);
return 0;
}

(A)
5
(B) 3
(C)
2
(D) 10
(E) Compilation error


Explanation:
**

11.

What will be output if you will execute following c code?

#include<stdio.h>
int main(){
    int i=5,j=10,num;
    num=++i,++j,i+j;
    printf("%d  %d  %d",num,i,j);
return 0;
}

(A) 5 5 10
(B) 5 6 11
(C) 6 5 12
(D) 6 6 11
(E) Compilation error


Explanation:
**

12.

What will be output if you will execute following c code?

#include<stdio.h>
float avg(float,float,float);
int main(){
    float p=1,q=2,r=-2,a;
    a=avg(p,(q=4,r=-12,q),r);
    printf("%f",a);
return 0;
}
float avg(float x,float y,float z){
    return (x+y+z)/3;
}
(A) 1.000000
(B) 0.000000
(C) 0.333333
(D) 1.333333
(E) Compilation error


Explanation:
**

13.

What will be output if you will execute following c code?

int main(){
    char c='\x15';
    char *ptr=&c;
    printf("%x",*ptr);   
return 0;
}

(A)
0x15
(B) 0X15
(C) 21
(D) 0x21
(E) Compilation error


Explanation:
**

14.

What will be output if you will execute following c code?

#include<stdio.h>
int main(){
    char array[]="Ashfaq \0 Kayani";
    char *str="Ashfaq \0 Kayani";
    printf("%s %c\n",array,array[2]);
    printf("%s %c\n",str,str[2]);
    printf("%d %d\n",sizeof(array),sizeof(str));
return 0;
}

(A)
Ashfaq h
Ashfaq h
16 2
(B)
Ashfaq h
Ashfaq Kayani h
2 16
(C)
Ashfaq Kayani h
Ashfaq h
16 2
(D)
Ashfaq h
Ashfaq h
2 16
(E) Compilation error


Explanation:
**

15.

What will be output if you will execute following c code?

#include<stdio.h>
union myStruct{
    int a;
    char b;
};
int main(){
    union myStruct ms={400};
    printf("%d  %d",ms.a,ms.b);
    return 0;
}

(A) 400 0
(B) 0 400
(C) 80 -112
(D) 400 -112
(E) Compilation error


Explanation:
**

16.

#include<stdio.h>
union cqbu{
    int a;
    char b;
};
struct cqbs{
    int a;
    char b;
};
int main(){
    struct cqbs s={25,50};
    struct cqbs *ps=(struct cqbs *)&s;
    union  cqbu *pu=(union  cqbu *)&s;
    printf("%d  %d\n",ps->a,ps->b);
    printf("%d  %d\n",pu->a,pu->b);
    return 0;
}

(A)
25 50
25 25
(B)
25 50
50 50
(C)
25 25
25 50
(D)
50 50
50 25
(E)
Compilation error


Explanation:
**

17.

int main(){
    float x;
    x=(int(float(double)5.5));
    printf("%f",x);
    return 0;
}

(A) 5.5
(B) 5.500000
(C) 5.000000
(D) 6.000000
(E) Compilation error


Explanation:

18.

What will be output if you will execute following c code?

int main(){
    float x;
    (int)x=5.8f;
    printf("%f",x);
    return 0;
}

(A) 5.800000
(B) 6.000000
(C) 7.000000
(D) 5.8
(E) Compilation error


Explanation:
**

19.

What will be output if you will execute following c code?

#include<stdio.h>
int main(){
    int a=5,b=10,c=15;
    int *arr[3]={&a,&b,&c};
    printf("%d",*arr[*arr[1]-8]);
return 0;
}

(A) 5
(B) 10
(C) 18
(D) Garbage value
(E) Compilation error


Explanation:
**

20.

What will be output if you will execute following c code?

#include<stdio.h>
int main(){
    int arr[][3]={{1,2},{3,4,5},{5}};
    printf("%d %d %d",sizeof(arr),arr[0][2],arr[1][2]);
return 0;
}

(A) 6  0 4
(B) 6  1 5
(C) 18 0 5
(D) 18 1 5
(E) Compilation error


Explanation:
**


Post a Comment