c practice test

What will be output if you will execute following c code?
#include<stdio.h>
int main(){
    int i;
    for(i=0;i<5;i++){
         int i=10;
         printf(" %d",i);
         i++;
    }
    return 0;
}
(A)
10 11 12 13 14
(B)
10 10 10 10 10
(C)
0 1 2 3 4
(D)
Compilation error
                         
2
What will be output if you will execute following c code?
#include<stdio.h>
int main(){
    register a,b,x;
    scanf("%d %d",&a,&b);
    x=a+~b;
    printf("%d",x);
    return 0;
}
(A)
0
(B)
It will be difference of a and b
(C)
It will be addition of a and b
(D)
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)
5
(B)
0
(C)
153
(D)
Compilation error
                         
4
What will be output if you will execute following c code?
#include<stdio.h>
int main(){
    register int a,b;
    int c;
    scanf("%d%d",&a,&b);
    c=~a + ~b + ++a + b++;
    printf(" %d",c);
    return 0;
}
//User input is: 1 2
(A)
-1
(B)
0
(C)
1
(D)
Compilation error
                         
5
What will be output if you will execute following c code?
#include<stdio.h>
int main(){
    int arr[3]={10,20,30};
    int x=0;
    x = ++arr[++x] + ++x + arr[--x];
    printf("%d ",x);
    return 0;
}
(A)
22
(B)
23
(C)
43
(D)
44
                         
6
What will be output if you will execute following c code?
#include<stdio.h>
int main(){
    int a[]={10,20,30,40};
    int i=3,x;
    x=1*a[--i]+2*a[--i]+3*a[--i];
    printf("%d",x);
    return 0;
}
(A)
30
(B)
60
(C)
90
(D)
Compilation error
                         
7
What will be output if you will execute following c code?
#include<stdio.h>
int main(){
    static int a[][2][3]={0,1,2,3,4,5,6,7,8,9,10,11,12};
    int i=-1;
    int d;
    d=a[i++][++i][++i];
    printf("%d",d);
    return 0;
}
(A)
9
(B)
10
(C)
11
(D)
Compilation error
                         
8
What will be output if you will execute following c code?
#include<stdio.h>
int f(int);
int main(){
    int i=3,val;
    val=sizeof (f(i)+ +f(i=1)+ +f(i-1));
    printf("%d %d",val,i);  
    return 0; 
}
int f(int num){
        return num*5;
}
(A)
2 3
(B)
4 3
(C)
3 2
(D)
Compilation error
                         
9
What will be output if you will execute following c code?
#include<stdio.h>
int main(){
    int x,a=3;
    x=+ +a+ + +a+ + +5;
    printf("%d  %d",x,a);
    return 0;
}
(A)
10 3
(B)
11 3
(C)
10 5
(D)
Compilation error
                         
10
What will be output if you will execute following c code?
#include<stdio.h>
int main(){
    int num,i=0;
    num=-++i+ ++-i;
    printf("%d",num);
    return 0;
}
(A)
0
(B)
1
(C)
-2
(D)
Compilation error
                         
11
What will be output if you will execute following c code?
#include<stdio.h>
int main(){
    int num,a=5;
    num=-a--+ +++a;
    printf("%d  %d",num,a);
    return 0;
}
(A)
1 5
(B)
-1 6
(C)
1 6
(D)
0 5
                         
12
What will be output if you will execute following c code?
#include<stdio.h>
int main(){
    int num,a=15;
    num=- - - -a--;
    printf("%d  %d",num,a);
    return 0;
}
(A)
15 14
(B)
14 15
(C)
14 14
(D)
15 15
                         
13
What will be output if you will execute following c code?
#include<stdio.h>
int main(){
    int x,a=2;
    x=++a,++a,a++;
    printf("%d  %d",x,a);
    return 0;
}
(A)
5 5
(B)
3 5
(C)
4 5
(D)
5 4
                         
14
What will be output if you will execute following c code?
#include<stdio.h>
int main(){
    int x,i=2;
    x=~-!++i;
    printf("%d",x);
    return 0;
}
(A)
-2
(B)
-1
(C)
0
(D)
1
                         
15
What will be output if you will execute following c code?
#include<stdio.h>
int main(){
    static double *p,*q,*r,*s,t=5.0;
    double **arr[]={&p,&q,&r,&s};
    int i;
    *p=*q=*r=*s=t;
    for(i=0;i<4;i++)
        printf("%.0f  ",**arr[i]);
    return 0;
}
(A)
5 5 5 5 5 
(B)
5 6 7 8 9
(C)
Infinite loop
(D)
Run time error

                         
16
What will be output if you will execute following c code?
#include<stdio.h>
int main(){
    float x;
    x=0.35==3.5/10;
    printf("%f",x);
    return 0;
}
(A)
0.000000
(B)
1.000000
(C)
0.350000
(D)
Compilation error
                         
17
#include<stdio.h>
int main(){
    int arr[]={6,12,18,24};
    int x=0;
    x=arr[1]+(arr[1]=2);
    printf("%d",x);
    return 0;
}
(A)
4
(B)
8
(C)
14
(D)
Compilation error
                         
18
What will be output if you will execute following c code?
#include<stdio.h>
int sq(int);
int main(){
    int a=1,x;
    x=sq(++a)+sq(a++)+sq(a++);
    printf("%d",x);
return 0;
}
int sq(int num){
    return num*num;
}
(A)
15
(B)
16
(C)
17
(D)
18
                         
19
What will be output if you will execute following c code?
#include<stdio.h>
int main(){
    printf("%c",*"abcde");
return 0;
}
(A)
acbcd
(B)
e
(C)
a
(D)
NULL
                         
20
What will be output if you will execute following c code?
#include<stdio.h>
int main(){
    printf("%d","abcde"-"abcde");
return 0;
}
(A)
0
(B)
-1
(C)
1
(D)
Garbage
                         

It is C programming language online test or quiz objective types questions answers with explanation for interview or written test. If you have any queries or suggestions, please share it.

  1.     #include <stdio.h>
  2.     main()
  3.     {
  4.         char *p = 0;
  5.         *p = 'a';
  6.         printf("value in pointer p is %c\n", *p);
  7.     }
a) It will print a
b) It will print 0
c) Compile time error
d) Run time error
View Answer
Answer:d
Output:
$ cc pgm.c
$ a.out
Segmentation fault (core dumped)
2. What is the output of this C code?
  1.    #include <stdio.h>
  2.    main()
  3.    {
  4.        if (sizeof(int) > -1)
  5.            printf("True");
  6.        else
  7.            printf("False");
  8.    }
a) True
b) False
View Answer
Answer:b
Output:
$ cc pgm.c
$ a.out
False
3. What is the output of this C code?
  1.     #include <stdio.h>
  2.     main()
  3.     {
  4.         char *p = "Sanfoundry C-Test";
  5.         p[0] = 'a';
  6.         p[1] = 'b';
  7.         printf("%s", p);
  8.     }
a) abnfoundry C-Test
b) Sanfoundry C-Test
c) Compile time error
d) Run time error
View Answer
Answer:d
Output:
$ cc pgm.c
$ a.out
Segmentation fault (core dumped)
4. What is the output of this C code?
  1.     #include <stdio.h>
  2.     int main()
  3.     {
  4.         float f = 0.1;
  5.         if (f == 0.1)
  6.             printf("True");
  7.         else
  8.             printf("False");
  9.     }
a) True
b) False
View Answer
Answer:a
Output:
$ cc pgm.c
$ a.out
False
5. What is the output of this C code?
  1.     #include <stdio.h>
  2.     main()
  3.     {
  4.         int n = 0, m = 0;
  5.         if (n > 0)
  6.             if (m > 0)
  7.                 printf("True");
  8.         else 
  9.             printf("False");
  10.     }
a) True
b) False
c) No Output will be printed
d) Run Time Error
View Answer
Answer:c
Output:
$ cc pgm.c
$ a.out
$

2 comments: