C online exam

C free online objective type exam for written test



Total marks : 60
For each correct answer : +3
For each incorrect answer: -1
Total time: 60 minutes
1.

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

#include<stdio.h>
int main(){
    int a=0;
    #if (a==0)
         printf("Equal");
    #else if
         printf("Not equal");
    #endif
    return 0;
}

(A) Equal
(B) Not equal
(C) null
(D) Garbage
(E) Compilation error


2.

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

#include<stdio.h>
int main(){
    for(;NULL;)
         printf("cquestionbank");
    return 0;
}

(A) c
(B) bank
(C) cquestionbank
(D) Infinite loop
(E) Compilation error


3.

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

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

(A)
0
(B) 1
(C) 154
(D) 155
(E) Compilation error


4.

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

#include<stdio.h>
void main(){
    int a=5;
    {
         int b=10;
         ++b;
         ++a;
         {
             int a=20;
             ++a;
             a=++b;
         }
         ++a;
         ++b;
         printf("%d %d",a,b);
    }
    printf(" %d",a);
}

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


5.

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

#include<stdio.h>
#include<conio.h>
void main(){
    int a[]={0,1,2,3,4,5,6,7,8,9,10};
    int i=0,num;
    num=a[++i+a[++i]]+a[++i];
    printf("%d",num);
}

(A) 6
(B)
7
(C) 8
(D) 9
(E) Compilation error


6.

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

#include<stdio.h>
#include<conio.h>
void main(){
    int i=3,val;
    val=sizeof f(i)+ +f(i=1)+ +f(i-1);
    printf("%d %d",val,i);
}
int f(int num){
    return num*5;
}

(A) 2 0
(B) 7 1
(C) 17 0
(D) 2 1
(E) Compilation error


7.

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

#include<stdio.h>
#include<conio.h>
void main(){
    int i;
    (i=8)+=1;
    printf("%d",i);
}

(A) 9
(B) 10
(C) 32
(D) 34
(E) Compilation error


8.

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

#include<stdio.h>
#include<conio.h>
void main(){
    char c=-'a';
    printf("%d",c);
}

(A) 65
(B) -65
(C) -a
(D) -97
(E)
Compilation error


9.

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

#include<stdio.h>
#include<conio.h>
void main(){
    int num,a=5;
    num=-a--;
    printf("%d  %d",num,a);
}

(A) 5  4
(B) -4 4
(C) -5 4
(D) -4 5
(E) Compilation error


10.

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

#include<stdio.h>
#include<conio.h>
void main(){
    int num,a=10;
    num=a&&0+ +-1&&a;
    printf("%d  %d",num,a);
}

(A) 1 1
(B) 0 0
(C) 1 10
(D) 0 10
(E) Compilation error


11.

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

#include<stdio.h>
#include<conio.h>
void main(){
    int x,y,z;
    y=(x=1,y=2,z=3);
    printf("%d  %d  %d",x,y,z);
}

(A) 1 2 3
(B) 1 1 3
(C) 1 3 3
(D) 1 0 3
(E) Compilation error


12.

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

#include<stdio.h>
#include<conio.h>
void main(){
    int t,a=5,b=10,c=15;
    t=(++a&&++b,++a),++a||++c;
    printf("%d  %d  %d %d",t,a,b,c);
}

(A) 7 8 11 15
(B) 6 7 10 14
(C) 1 8 10 15
(D) 6 18 11 15
(E) Compilation error


13.

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

#include<stdio.h>
#include<conio.h>
int a=5;
void main(){
    int x;
    x=!a+change();
    printf("%d",x);
}
int change(){
    a=0;
    return 0;
}

(A) 0
(B) 5.000000
(C) 0.000000
(D) 1.000000
(E) Compilation error


14.

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

#include<stdio.h>
typedef struct cquestionbank{
    int num;
    struct cquestionbank **p;
    struct cquestionbank ***q;
}cqb;
int main(){
    static cqb *var1,**var2;
    cqb temp={5,&var1,&var2};
    var2=&var1;
    var1->num=25;
    printf("%d  %d ",**(temp.q),***(temp.q));
    return 0;
}

(A) 0 5
(B) 0 25
(C) 5 25
(D) 25 5
(E) Compilation error


15.

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

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

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


16.

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

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

(A) 0
(B) 0.000000
(C) 1.000000
(D) 3.000000
(E) Compilation error


17.

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

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

(A) 7.000000
(B) 7.800000
(C) 8.000000
(D) 8.100000
(E) Compilation error


18.

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

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

(A) 0.000000
(B) 1.000000
(C) 3.000000
(D) 3.300000
(E) Compilation error


19.

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

#include "string.h"
typedef struct stu1{
    int roll;
    char *name;
    double marks;
}STU1;
typedef struct stu2{
    int roll;
    char *name;
    double marks;
}STU2;
void main(){
    STU1 s1={25,"Rohit",87.43},*p1;
    static STU2 *p2;
    p1=&s1;
    memccpy(p2,p1,'\0',sizeof(STU1));
    printf("Roll  : %d\n",p2->roll);
    printf("Name  : %s\n",p2->name);
    printf("Marks : %lf",p2->marks);
}

(A)
Roll  : 25
Name  : (null)
Marks : 0.000000
(B)
Roll  : 25
Name  : rohit
Marks : 0.000000
(C)
Roll  : 25
Name  : rohit
Marks : 87.430000
(D)
Roll  : 0
Name  : (null)
Marks : 0.000000
(E) Compilation error


20.

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

#include<stdio.h>
#define value 30
int main(){
    #if max
         printf("Defined");
    #else
         printf("Not defined");
    #endif
    return 0;
}
(A)
Defined
(B) Not defined
(C) null
(D) Run time error
(E) Compilation error




If you have any queries or suggestions in above c online exam, please share it.

40 comments:

Anonymous said...

Could anyone please point me to an explanation of Q5. It's driving me mad! Thanks.

yogesh_madhuri said...

i is incremented 3 times hence i becomes 3 then
num=a[++i+a[++i]]+a[++i];

num=a[3+a[3]]+a[3]=a[3+3]+3=a[6]+3=6+3=9

jagdish said...

explanation for Q1,7,13,18,19 pls.............if any1 knows.........thnx in advance.........

Unknown said...

can any body make understand of logic of q6.

Anonymous said...

@pavan
sizeof f(i)=2,
f(1)=1*5=5,
f(0)=0*5=0,

val=2+5+0;
i=1 //as f(i=1) changes the value of i in memory

Anonymous said...

can anyone plz explain the ques no 16 and 18,both are mostly same just a difference of 3.5 and 3.3 then how the answers are different?can anyone explain plzzzzzz

Anonymous said...

Q 7 correct answer is E
error:Lvalue required!!

Anonymous said...

Ans of Q.7 is 9.

Anonymous said...

Q7 Compiled in vc
error C2106: '+=' : left operand must be l-value

sai said...

explain me 12,14,15,19

Anonymous said...

the answer of 1st question is (a) equal.......

Anonymous said...

seventh question answer is A not D

since i=8 and i=i+1; then i=9

kam said...

hi have anyone tried 2 question. i am compiling in linux gcc compiler and getting no answer
it just runs but no out put but here its written that it gives an output at option c .

Ankita said...

answer to 1 question is e only. because #if is a preprocessor.
Answer to question 7 is since (i=8) will be evaluated first which will be a constant value and thus a lvalue error

Ankita said...

answer to question 13 must be a i.e 0

Sunita said...

really good job ... questions quality is bessst ... :)

vivek said...

ans to question no .6 on compilation i got val=9 and i=1.here given val=7 and i=1...can anyone plz explain

Anonymous said...

i thnk some answers are wrong...


can u plz reevaluate the answers???

Anonymous said...

please do make questions which do not include 'compilation error' as an option! Thank you!

Unknown said...

answer for the question 13 is i.e, x=!a+change(); is 0

prathi said...

convert 3.5 as binary 0000 0011.1(non repeating) where as 3.3 in binary form is
0000 0011.010011001..(the last 1001 bits are reoccuring) real data by default is considered as double(ie 8 bytes) so the representation in IEEE of duble for 3.3(reoccuring bits after decimal)is differnt from IEEE form of float .

but in case of 3.5 there is only an additional increase in number of 0's in double IEEE from that of float IEEE.
hence (float)3.5 == 3.5 .

Anonymous said...

Please tell me the explaination for the q4

Anonymous said...

Output of Q.1 is Equal..how??

shristika said...

int a=5;
{
int b=10;
++b; //b=11
++a; //a=6
{
int a=20;
++a; //a=21
a=++b; //b=12
} // a=21 closes here
++a; //a=7
++b; //b=13
printf("%d %d",a,b); //a=7, b=13
}
printf(" %d",a); //a=7
}

Anonymous said...

can you tell me output of first question?

Anonymous said...

nice set of question

matheen smart vip said...

a[++i+a[++i]]+a[++i];
ans:7.
exp: precedence level start from left to right this square bracket [].
i=0;
a[++i+a[++i]]=a[2 + a[2]]+a[3]=a[4]+a[3]=7.

note;after incrementing allocating the same variable value in same i th location it is a[2+a[2]].now adding a[4].
bcz precedence level are low in '+' addition .don’t think a[2+a[1]] i is the only memory location here it will change

matheen smart vip said...

#include
#include
void main(){
int i=3,val;
val=sizeof f(i)+ +f(i=1)+ +f(i-1);
printf("%d %d",val,i);
}
int f(int num){
return num*5;
}
...........................

function returns decimal means it is a integer so memory size is 4 bytes and rest of thing is 5 and 0
output is 4+5+0=9 .............ok

Pratik said...

please code me

*
* *
* * *
1 * * * *

where [1=space]

Anonymous said...

#preprocessor is just a Text-Replace, the compiler gets if (without #)

Anonymous said...

Q14, should be runtime error or core dump since var1 does not point any. Am I wrong? Can somebody clarify this?

Anonymous said...

For Q19, I think it should be core dump as like Q14 because memccpy(p2,p1,'\0',sizeof(STU1));

Am I wrong? Can somebody clarify

Unknown said...

Can anybody give brief explanation on all ques solutions??........plzzzzz

Unknown said...

Can anybody explain the ques 11,12,13,19....plzz

Unknown said...

#include
int main(){
int a=0;
#if (a==0)
printf("Equal");
#else if
printf("Not equal");
#endif
return 0;
}
already we intialized that a==0 then it 0==0 means the comparision its true then the output be printed as equal

Unknown said...

Correct answer is 7

Unknown said...

hi i need q14.
#include
typedef struct cquestionbank{
int num;
struct cquestionbank **p;
struct cquestionbank ***q;
}cqb;
int main(){
static cqb *var1,**var2;
cqb temp={5,&var1,&var2};
var2=&var1;
var1->num=25;
printf("%d %d ",**(temp.q),***(temp.q));
return 0;
}

explanation clearly....i have little bit confuse...please explain clearly
thanks for advance,
ramesh

Unknown said...

q 12: 7 8 11 15,how the c value comes to 15

Unknown said...

Q1 answer should be "Equal" not compilation error

Sanju said...

Plzz explain question no:5