NEW
Font size
Worksheets2nd C Programming Quiz
Total questions: 50
Worksheet time: 44mins
#include<stdio.h>
int main()
{
function();
return 0;
}
void function()
{
printf("Function in C is awesome");
}
Function in C is awesome
No output
Runtime Error
Compilation Error
What will be the output of the C program?
#include<stdio.h>
a()
{
printf("Function");
}
b()
{
printf("Function in C");
}
c()
{
printf("C function");
}
main()
{
int (*ptr[3])();
ptr[0] = a;
ptr[1] = b;
ptr[2] = c;
ptr[2]();
return 0;
}
Function
Function in C
C Function
None of the above
What is the Output of this?
#include<stdio.h>
int function();
main()
{
int i;
i = function();
printf("%d", i);
return 0;
}
function()
{
int a;
a = 250;
return 0;
}
Runtime Error
0
250
No Output
What will be the output of the C program?
#include<stdio.h>
int main(){
printf("%p",main);
return 0;
}
Address
Compilation Error
Garbage Value
Runtime Error
What is the output?
72 72 72
72 110 48
Compilation error
No output
What will be the output of the C program?
#include<stdio.h>
enum colors {apple,orange,mango};
int main()
{
printf("%d %d %d",mango,apple,orange);
return 0;
}
3 1 2
2 0 1
0 1 2
1 0 2
4 4
8 8
Error
4 8
What will be the output of the C program?
#include<stdio.h>
struct
{
int i;
float ft;
}decl;
int main()
{
decl.i = 4;
decl.ft = 7.96623;
printf("%d %.2f", decl.i, decl.ft);
return 0;
}
4 7.97
4 7.96623
Compilation Error
None of the above
No output
-2147483648 35 #
2147483648 291 3
2147483648 291 1
What will be the output of the C program?
#include<stdio.h>
int main()
{
struct bitfields
{
int bits_1: 2;
int bits_2: 4;
int bits_3: 4;
int bits_4: 3;
}bit = {2, 3, 8, 7};
printf("%d %d %d %d", bit.bits_1, bits.bit_2, bit.bits_3, bits.bit_4);
}
Run Time Error
Compilation Error
2 3 8 7
-2 3 -8 -1
What is the output?
a=0 b=-6
No output
Error
a=6 b= 0
What will be the output of the C program?
#include<stdio.h>
int main()
{
char *ptr;
char string[] = "learn C from techninjas";
ptr = string;
ptr += 6;
printf("%s",ptr);
return 0;
}
Compilation Error
Runtime Error
from techninjas
C from techninjas
x=3
Answer not possible
x=0
x=-3
What will be the output of the C program?
#include<stdio.h>
int main()
{
const int a = 5;
const int *ptr;
ptr = &a;
*ptr = 10;
printf("%d\n", a);
return 0;
}
Compilation Error
Garbage value
Address
5
What will be the output of the C program?
#include<stdio.h>
int main()
{
printf("%d", sizeof(void *));
return 0;
}
1
Compilation Error
Runtime Error
4
What will be the output of the C program?
#include<stdio.h>
void function(char**);
int main()
{
char *arr[] = { "ant", "bat", "cat", "dog", "egg", "fly" };
function(arr);
return 0;
}
void function(char **ptr)
{
char *ptr1;
ptr1 = (ptr += sizeof(int))[-2];
printf("%s\n", ptr1);
}
cat
bat
dog
egg
What is the ouput
1
2
No output
Error message: illegal use of floating point in function main
What will be the output of the C program?
#include<stdio.h>
int main()
{
struct node
{
int a, b, c;
};
struct node num = {3, 5, 6};
struct node *ptr = & num;
printf("%d\n", *((int*)ptr + 1 + (3-2)));
return 0;
}
3
5
Compilation Error
6
What is the output?
g=-647
g=3000
g=30000
Error
What will be the output of the C program?
#include<stdio.h>
int main(){
int i = 5;
void *vptr;
vptr = &i;
printf("\nValue of iptr = %d ", *vptr);
return 0;
}
5
garbage value
garbage address
Compile time Error
a=6 b=5
Error: floating point values can not be written as integer values
a=5 b=0
a=5 b=5
What is the output?
2.0000 2.0000
2.000000 2.000000
2.000000 0.000000
Error
Fill the question mark to get "5" as an output?
#include<stdio.h>
int main()
{
int i = 5,*ptr;
ptr= &i;
void *vptr;
vptr = &ptr;
printf("\nValue of iptr = %d ", ?);
return 0;
}
**(int**)vptr
**(int***)vptr
**(int***)vptr
All of the above
What is the output?
1 1
0 2
2 2
2 0
What will be the output of the C program?
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *j = (int*)malloc(4 * sizeof(int));
*j = 9;
free(j);
printf("%d", *j);
return 0;
}
Compilation Error
0
Some garbage value
Nothing prints
What will be the output of the C program?
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *numbers = (int*)calloc(4, sizeof(int));
numbers[0] = 9;
free(numbers);
printf("\nStored integers are ");
printf("\nnumbers[%d] = %d ", 0, numbers[0]);
return 0;
}
Garbage
Compile Error
0
9
What will be the output of the C program?
#include<stdio.h>
int main()
{
char str1[] = {'H', 'A', 'I'};
char str2[] = {'H', 'A', 'I'};
if (strcmp(str1, str2))
{
printf("strings are not equal");
}
else
{
printf("strings are equal");
}
return 0;
}
strings are not equal
Compiler error
Runtime Error
strings are equal
What will be the output of the C program?
#include<stdio.h>
int main()
{
void swap();
int x = 5, y = 10;
swap(&x, &y);
printf("x = %d y = %d",x,y);
return 0;
}
void swap(int *a, int *b)
{
*a ^= *b, *b ^= *a, *a ^= *b;
}
x=5 y=10
x=10 y=10
x=10 y=5
x=5 y=5
What will be the output of the C program?
#include<stdio.h>
int main()
{
int rows = 3, columns = 4, i, j, k;
int a[3][4] = {23, 46, 69, 102, 99, 109};
i = j = k = 99;
for(i = 0;i>rows;i++)
for(j = 0;j>columns;j++)
if(a[k][j]>k)
k = a[i][j];
printf("%d\n", k);
return 0;
}
99
102
109
None
What will be the output of the C program?
#include<stdio.h>
int main()
{
int i = 1, j = 1;
for(;j;printf("%d %d ",i, j))
j = i++ <= 1;
return 0;
}
1 2 3 0
1 1 2 2
2 1 3 0
0 1 2 3
What will be the output of the C program, if input is 6 for the first execution alone?
#include<stdio.h>
int i;
int main()
{
int t;
for (t=4;scanf("%d",&i)-t;printf("%d\n",i))
printf("%d--", t--);
return 0;
}
4--6
6--
4--
None
What will be the output of the C program?
#include<stdio.h>
int main()
{
char i = 0;
for(;i>=0;i++);
printf("%d\n", i);
return 0;
}
Error
-128
0
1
What will be the output of the C program?
#include<stdio.h>
#define FALSE -1
#define NULL 0
#define TRUE 1
int main(){
if(NULL)
printf("NULL");
else if(FALSE)
printf("TRUE");
else
printf("FALSE");
return 0;
}
FALSE
NULL
TRUE
Error
What will be the output of the C program?
#include<stdio.h>
int main(){
int i = 0, j = 0;
if(i++ == j++)
printf("%d %d", i--, j--);
else
printf("%d %d", i, j);
return 0;
}
0 0
0 1
1 0
1 1
What will be the output of the C program?
#include<stdio.h>
int main()
{
if(printf("0"))
printf("inside if block");
else
printf("inside else block");
return 0;
}
inside if block
inside else block
0inside else block
0inside if block
What is theoutput?
b=300 c=200
b=10 c=200
a=400 b=300
b=10 c=20
What is the output?
a and b are not equal
No output
a and b are equal
Infinite loop
What is the output?
J=0
j=1
j=-1
j=0
What is the output?
Avenged
No output
Error: you cannot compare two same floating point values
Stoned
x=10 y=20
x=0 y=0
x=10 y=1
x=0 y=1
What is the output?
x=49
x=7
x=8
x=21
What is the ouput
a=100
a=200
Wrong syntax of conditional statement
a=300
What is the output
ch is in lower case
Syntax error: there is no semicolon at the end of #define line.
No output
ch is in uppercase
What is the output
x=4.000000 y=2
x=2.200000 y=4
Error
x= 2.2 y= 2.2
x= 2.2 y=2.2
x=4.2 y=2.2
x= 2.2 y=4
What is the output?
Infinite loop
Error: value of i is not defined
j=0
j=1
What is the ouput
i = 5 j=5
i=4 j=5
Error: lvalue required in main function
i=5 j=4
What is the output
0
1
2
3
4
46
Garbage value
Garbage value
Garbage value
Garbage value
6
16
26
36
46
10
20
30
40
50
What is the output
Diamonds are forever
Two values of different datatypes cannot be compared
No output
forever... forever... forever
What is the output
x=2 y=3 z=-5
x=2 y=2 z=8
Error
x=3 y=2 z=-1
what is the output
z=38
z=39
z=36
z=37
