C online practice test

C free online practice test questions and answers


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

What will be output of following c program?

#include<stdio.h>
#define max
int main(){
    printf("%d",max);
    return 0;
}

(A) 0
(B) null
(C) Garbage
(D) -1
(E) Compilation error

2.

What will be output of following c program?

#include<stdio.h>
int main(){
    for(printf("1");!printf("0");printf("2"))
         printf("Sachin");
    return 0;
}

(A) 10sachin2
(B) 10sachin
(C)  10sachin210sachin2
(D) 10
(E) Compilation error

3.

What will be output of following c program?

#include<stdio.h>
int main(){
    int a=5;
    static int b=a;
    printf("%d %d",a,b);
    return 0;
}
(A) 5   5
(B) 5   0
(C) 5   null 
(D) 5   Garbage
(E) Compilation error

4.

What will be output of following c program?

#include<stdio.h>
void main(){
    int i;
    for(i=0;i<5;i++){
         int x=0;
         printf("%d",x);
         x++;
    }  
}

(A) 01234
(B) 001234
(C) 0000
(D) Infinite loop
(E) Compilation error

5.

What will be output of following c program?

#include<stdio.h>
#include<conio.h>
void main(){
    int a[]={5,10,15};
    int i=0,num;
    num=a[++i]+ ++i+(++i);
    printf("%d",num);
}

(A) 6
(B) 17
(C) 16
(D) 12
(E) Compilation error

6.

What will be output of following c program?

#include<stdio.h>
#include<conio.h>
void main(){
    int i=3,val;
    val=f(i)+ +f(i=1)+ +f(i-1);
    printf("%d",val);
}
int f(int num){
    return num*5;
}
(A) 30
(B) 20
(C) 21
(D) 31
(E) Compilation error

7.

What will be output of following c program?

#include<stdio.h>
#include<conio.h>
long fu(int);
char vect[]={1,2,3,4,5};
void main(){
    int i=1;
    i=fu(++i)+ ++vect[++i]+ ++i+fu(i++);
    printf("%d",i);
}
long fu(int x){
    return x*3;
}

(A) 31
(B) 32
(C) 33
(D) 34
(E) Compilation error

8.

What will be output of following c program?

#include<stdio.h>
#include<conio.h>
void main(){
    int a,i=4;
    a=- -i+- -i+- -5;
    printf("%d %d",a,i);
}
(A) 13  4
(B) -3  2
(C) 7   2
(D) -13 4
(E) Compilation error

9.

What will be output of following c program?

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

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

10.

What will be output of following c program?

#include<stdio.h>
#include<conio.h>
void main(){
    int num,a=10;
    num=a--- -a--;
    printf("%d  %d",num,a);
}
(A) 0 8
(B) 0 10
(C) 20 8
(D) -1 10
(E) Compilation error

11.

What will be output of following c program?

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

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

12.

What will be output of following c program?

#include<stdio.h>
#include<conio.h>
void main(){
    int i=5,j=10,num;
    num=(++i,++j,i+j);
    printf("%d  %d  %d",num,i,j); 
}
(A) 17  6  11
(B) 6   6  11
(C) 15  6  11
(D) 15  5  10
(E) Compilation error

13.

What will be output of following c program?

#include<stdio.h>
#include<conio.h>
float avg(float,float,float);
void main(){
    float p=1,q=2,r=-2,a;
    a=avg(p,(q=4,r=-12,q),r);
    printf("%f",a); 
}
float avg(float x,float y,float z){
    return (x+y+z)/3;
}

(A) 0.111111
(B) 1.000000
(C) -0.777777
(D) -1.000000
(E) Compilation error

14.

What will be output of following c program?

#include<stdio.h>
int main(){
    float **(*ptr)[4]=(float **(*)[4])0;
    ptr+=5;
    printf("%d  %d",ptr,sizeof ptr);
    return 0;
}

(A) 0  2
(B) 5  2
(C) 4  2 
(D) 40 2
(E) Compilation error

15.

What will be output of following c program?

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

(A) 400 A
(B) 400 65
(C) 400 97
(D)
0  0
(E) Compilation error

16.

What will be output of following c program?

#include<stdio.h>
int main(){
    float x;
    x=(int)5.6f*3.2f/sizeof((int)6.6);
    printf("%f",x);
    return 0;
}

(A) 8.960000
(B) 9.600000
(C) 8.000000
(D) 2.000000
(E) Compilation error

17.

What will be output of following c program?

#include<stdio.h>
#define plus +
#define minus +plus
int main(){
    long x,i=3;
    x=+ + i;
    printf("%ld",x);
    return 0;
}
(A) 4
(B) 3
(C) 0
(D) 6
(E) Compilation error

18.

What will be output of following c program?

#include<stdio.h>
int main(){
    float x;
    x=(int)1.1,(float)2.2,(int)3.3 ,5.4;
    printf("%f",x);
    return 0;
}

(A) 1.000000
(B) 5.400000
(C) 2.200000
(D) 3.300000
(E) Compilation error

19.

What will be output of following c program?

#include<stdio.h>
#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;
    STU2 *p2;
    p1=&s1;
    memcpy(p2,p1,4);
    printf("Roll  : %d\n",p2->roll);
    printf("Name  : %s\n",p2->name);
    printf("Marks : %lf",p2->marks);  
}

(A)

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

20.

What will be output of following c program?

#include "string.h"
typedef struct stu1{
    char name1[6];
    char name2[6];
    double marks;
}STU1;
void main(){
    STU1 s1={"rohit","kumar",87.43},*p1;
    char *p;
    p1=&s1;
    p=memchr(p1,'u',sizeof(STU1));
    printf("%s",p); 
}
(A) r
(B) rohit
(C) umar
(D) rohit kumar
(E) Compilation error



If you have any queries or suggestions in above C online practice test, please share it.

21 comments:

Anonymous said...

It will be helpful if the explanation for the solutions is provided.It is difficult to understand.

tapiwa takaindisa said...

guys can you help me find an online tutor,c programming is not easy for me.

Raseeth said...

It wil be very useful if explanation like before exams. plz give pxplanations

Anonymous said...

plz explain 14th one.

Anonymous said...

plz explain 14th & 20th

rajendra said...

provide exaplations.... if u provide it will be very helpful.

Anonymous said...

output of Q5 will be 15 and its not in option

Anonymous said...

#include
int main(){
for(printf("1");!printf("0");printf("2"))
printf("Sachin");
return 0;

I think it is like this

for loop // it prints the value "1"
then it checks the condition part and prints "0" and once it prints 0 it returns true(1) and since its !printf("0") it will consider it as
!true=>!1=>0 so it wont proceed further and hence the output 10

Anonymous said...

but can u please tell how will it be 15?

Unknown said...

it's difficult to me

Unknown said...

variable declarations withn a for loop.
Q4 is it possble in C? :P LOL

Unknown said...

anyone can be explain me Q7?

Unknown said...

please append explanation and provide link for detailed description....hope to see soon...

Unknown said...

please append explanation and provide link for detailed description....hope to see soon...

Unknown said...

int z=(5,3,2); why z is assigned last value

Unknown said...

Q5 answer should be 21. Precedence order - Higher to Lower - () then [] then ++ then +

so after increment value of i will be 3, hence a[3] + 3 + 3 = 21.

Unknown said...

q.5 - ans. is 19

Unknown said...

Q.5, Ans:- 19

Anonymous said...

1 a=5,6
a is assigned to 5 .
2 a=(5,6);//comma operator works left to right but returns ri8 most value
a is assigned to 6

Siddharth said...

there exists nothing such as a[3] in the program @bhanu, only what you have is a[0],a[1],a[2]

Unknown said...

it should be 15