WorksheetsC Code Based Test
Total questions: 160
Worksheet time: 3hrs 37mins
#include<stdio.h>
int main(){
int i=5;
printf("%d%d%d%d%d",i++,i--,++i,--i,i);
}
4 5 5 4 5
3 4 5 6 1
3 4 4 3 4
6 4 4 6 4
#include<stdio.h>
int main(){
int i;
printf("%d",scanf("%d",&i));
}
1
0
2
3
#include<stdio.h>
#define clrscr() 100
int main(){
clrscr();
printf("%d/n",clrscr());
}
100
101
103
200
int main()
{
char p;
char buf[10] = {1,2,3,4,5,6,9,8};
p=(buf+1)[5];
printf(“%d”,p);
}
8
7
9
6
What will be the output of the following C code snippet?
#include <stdio.h>
void main()
{
1 < 2 ? return 1: return 2;
}
returns 1
returns 2
varies
compile time error
#include<stdio.h>
void f() {
static int i;
++i;
printf("%d", i); }
main(){
f();
f();
f();
}
135
234
123
678
main()
{
Int c = --2;
Printf(“c = %d”,c);
}
1
0
2
Error
int main()
{
int i=-1,j=-1,k=0,l=2,m;
m = i++&&j++&&k++||l++;
printf(“%d%d%d%d%d”,i,j,k,l,m);
}
00131
11242
00242
23456
main(){
int a;
printf(“TIGER COUNT = “);
a = show();}
int show(){
return 15;
return 35;
}
TIGER COUNT =15
TIGER COUNT =30
TIGER COUNT =35
TIGER COUNT =15 35
main()
{
int c[ ]={2.8,3.4,4,6.7,5};
int j,*p=c,*q=c;
for(j=0;j<5;j++) {
printf(" %d ",*c);
++q; }
for(j=0;j<5;j++){
printf(" %d ",*p);
++p; }
}
1 1 1 1 1 1 2 3 4 5
2 2 2 2 2 2 3 4 5 6
2 2 2 2 2 2 3 4 6 5
3 3 3 3 3 3 4 5 6 7
main()
{
extern int i;
i=20;
printf("%d",i);
}
20
25
1
undefined symbol i
#include<stdio.h>
int main()
{
int a, b = 10;
a = -b--;
printf("a = %d, b = %d", a, b);
return 0;
}
a = 10,b = 8
a = 11,b = 7
a = 12,b = 10
a = -10, b = 9
What will be the output of the following statements ?
int x[4] = {1,2,3};
printf("%d %d %D",x[3],x[2],x[1]);
03%D
000
032
321
What will be the output of the following program ?
#include
void main()
{
int a = 36, b = 9;
printf("%d",a>>a/b-2);
}
9
7
5
None
What would be the output of the following program?
#include
main()
{
char str[]="S\065AB";
printf(" %d", sizeof(str));
}
7
6
5
Error
What will be output if you will compile and execute the following c code?
struct marks{
int p:3;
int c:3;
int m:2;
};
void main(){
struct marks s={2,-6,5};
printf("%d %d %d",s.p,s.c,s.m);
}
2 -6 5
2 -6 1
2 2 1
Compile Error
What will be output if you will compile and execute the following c code?
#define call(x) #x
void main(){
printf("%s",call(c/c++));
}
c
c++
#c/c++
c/c++
What is output of below program?
int main()
{
int i,j,count;
count=0;
for(i=0; i<5; i++);
{
for(j=0;j<5;j++);
{
count++;
}
}
printf("%d",count);
return 0;
}
55
54
1
0
What is output of below program?
int main()
{
int i,j,k,count;
count=0;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
count++;
}
}
printf("%d",count);
return 0;
}
5
10
25
50
What is output of below program?
int main()
{
int i,j;
for(i = 0,j=0;i<5;i++)
{
printf("%d%d--",i,j);
}
return 0;
}
0--01--12--23--34--
00--10--20--30--40--
Compile Error
00--01--02--03--04--
What is output of below program?
int main()
{
int i;
for(i=0; i<5; ++i++)
{
printf("Hello");
}
return 0;
}
Hello is printed 5 times
Compilation Error
Hello is printed 2 times
Hello is printed 3 times
What is the output of below program?
int main()
{
int i;
for(i = 0,i<5,i++)
{
printf("Hello");
}
return 0;
}
Hello is printed 5 times
Compile Error
RunTime Error
Hello is printed 4 times
What is the output of below program?
int main()
{
for(; ;)
for(; ;)
printf("Hello..");
return 0;
}
Compile Error
RunTime Error
Hello is printed infinite times
Hello is printed one time
(24)
What is output of below code?
int main()
{
char name[]="Cppbuz";
int len;
int size;
len = strlen(name);
size = size_of(name);
printf("%d,%d",len,size);
return 0;
}
6,6
6,7
7,7
7,6
What is storage class for variable A in below code?
int main(){
int A;
A = 10;
printf("%d", A);
return 0;}
extern
auto
register
static
What is the output of C Program.?
int main()
{
int a=5;
while(a >= 3);
{
printf("RABBIT\n");
break;
}
printf("GREEN");
return 0;
}
GREEN
RABBIT GREEN
RABBIT is printed infinite times
None of the above
What will be the output of the following C code?
#include <stdio.h>
void main()
{
float x = 0.1;
printf("%d, ", x);
printf("%f", x);
}
0.100000, junk value
Junk value, 0.100000
0, 0.100000
0, 0.999999
int x=1;
double y= 0.5 * (exp (x) + exp (-x));
cos(x)
cosh(x)
fmod(x)
modf(x)
What will be the output of the following C code if the system time is 1:52 PM (Sunday)?
#include<stdio.h>
#include<time.h>
int main()
{
struct tm *ptr;
time_t t;
char str[100];
t = time(NULL);
ptr = localtime(&t);
strftime(str,100,"%I",ptr);
puts(str);
return 0;
}
error
01
1
13
What is the meaning of the following C code if output is 0?
#include<stdio.h>
#include<time.h>
int main()
{
struct tm *local;
time_t t;
t=time(NULL);
local=localtime(&t);
printf("%d",local->tm_isdst);
return 0;
}
DST is in effect
DST status is unknown
DST is not in effect
DST is corresponding with local time
What will be the output of the following C code?
#include <stdio.h>
void main()
{
register int x = 0;
if (x < 2)
{
x++;
main();
}
}
Segmentation fault
main is called twice
main is called once
main is called thrice
What will be the output of the following C code?
#include <stdio.h>
struct point
{
int x;
int y;
};
void foo(struct point*);
int main()
{
struct point p1[] = {1, 2, 3, 4};
foo(p1);
}
void foo(struct point p[])
{
printf("%d\n", p[1].x);
}
compile error
1
3
2
What will be the output of the following C code?
#include <stdio.h>
void main()
{
float x;
int y;
printf("enter two numbers \n");
scanf("%f %f", &x, &y);
printf("%f, %d", x, y);
}
7.000000, 7
Run time error
7.000000, junk
Varies
What is the output of the following C code if there is no error in stream fp?
#include <stdio.h>
int main()
{
FILE *fp;
fp = fopen("newfile", "w");
printf("%d\n", ferror(fp));
return 0;
}
Compilation error
0
1
none
What will be the output of the following C code?
#include <stdio.h>
int x = 0;
void main()
{
int *const ptr = &x;
printf("%p\n", ptr);
ptr++;
printf("%p\n ", ptr);
}
0 1
Compile time error
0xbfd605e8 0xbfd605ec
0xbfd605e8 0xbfd605e8
What will be the output of the following C code?
#include <stdio.h>
int main()
{
double ptr = (double )100;
ptr = ptr + 2;
printf("%u", ptr);
}
115
102
116
108
Identify X library function for line input and output in the following C code?
#include <stdio.h>
int X(char s, FILE iop)
{
int c;
while (c = *s++)
putc(c, iop);
return ferror(iop) ? EOF : 0;
}
getc
putc
fgets
fputs
What will be the output of the following C code?
#include <stdio.h>
#define foo(x, y) x / y + x
int main()
{
int i = -6, j = 3;
printf("%d\n",foo(i + j, 3));
return 0;
}
Divided by zero exception
Compile time error
-8
-4
Which part of the program address space is p stored in the following C code?
#include <stdio.h>
int *p;
int main()
{
int i = 0;
p = &i;
return 0;
}
Code/text segment
Data segment
Bss segment
Stack
What will be the output of the following C code?
#include <stdio.h>
int main()
{
int n;
scanf("%d", &n);
ungetc(n, stdin);
scanf("%d", &n);
printf("%d\n", n);
return 0;
}
Compile time error
Whatever is typed by the user first time
Whatever is typed by the user second time
Undefined behaviour
What will be the output of the following C code?
main()
{
enum resut {pass, fail};
enum result s1,s2;
s1=pass;
s2=fail;
printf("%d",s1);
}
error
fail
pass
0
What will be the output of the following C code?
#include <stdio.h>
int (*(x()))[2];
typedef int (*(*ptr)())[2] ptrfoo;
int main()
{
ptrfoo ptr1;
ptr1 = x;
ptr1();
return 0;
}
int (*(x()))[2]
{
int (*ary)[2] = malloc(sizeof*ary);
return &ary;
}
Compile time error
Undefined behaviour
Depends on the standard
none
Which of the following should be used for freeing the memory allocated in the following C code?
#include <stdio.h>
struct p
{
struct p *next;
int x;
};
int main()
{
struct p p1 = (struct p)malloc(sizeof(struct p));
p1->x = 1;
p1->next = (struct p*)malloc(sizeof(struct p));
return 0;
}
free(p1);
free(p1->next)
free(p1->next); free(p1);
free(p1);
all of the mentioned
What will be the output of the following C code?
#include <stdio.h>
struct student
{
char *c;
struct student *point;
};
void main()
{
struct student s;
struct student m;
s.c = m.c = "hi";
m.point = &s;
(m.point)->c = "hey";
printf("%s\t%s\t", s.c, m.c);
}
hey hi
hi hey
hey hey
runtime error
What will be the output of the following C code?
#include <stdio.h>
void main()
{
char *a[10] = {"hi", "hello", "how"};
int i = 0;
for (i = 0;i < 10; i++)
printf("%s", *(a[i]));
}
segmentation fault
hi hello how followed by 7 null values
10 null values
depends on compiler
1.What will be the output of the following C code on a 32-bit system?
10
13
run time error
40
2.What will be the output of the following C code?
102
104
108
116
What will be the output of the following C code?
str1 is not greater than str2
str2 is not greater than str1
both are equal
error in given code
What will be the output of the following C code?
6 7
6 6
5 5
5 6
What will the following C code do?
find last occurrence of c in char s[ ].
find first occurrence of c in char s[ ].
find the current location of c in char s[ ].
There is error in the given code
What will be the output of the following C code?
Compilation error
1 2 3
1 2
1 3
What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard input)
1
compile error
2
run time error
What will be the output of the following C code?
Loop Loop
Compilation error
Loop Loop Loop Loop
Infinite Loop
What will be the output of the following C code? (Assuming size of int be 4)
4
12
16
Can’t be estimated due to ambiguous initialization of array
What will be the output of the following C code?
i value is 1 and j value is 1
i value is 0 and j value is 0
i value is 1 and j value is undefined
i and j value are undefined
What will be the output of the following C code?
37
Compile time error
Varies
Depends on compiler
The correct syntax to access the member of the ith structure in the array of structures is?
s.b.[i];
s.[i].b;
s.b[i];
s[i].b;
What will be the output of the following C code?
1 2 3 4 5
1 2 3 4
Compile time error
Stack overflow
What will be the output of the following C code?
9
11
12
21
What will be the output of the following C code?
Compile time error
Varies
hi
h
Which option should be selected to work the following C expression?
typedef char [] string;
typedef char *string;
typedef char [] string; and typedef char *string;
Such expression cannot be generated in C
What will be the output of the following C code?
segmentation fault
hi hello how followed by 7 null values
10 null values
depends on compiler
What will be the output of the following C code? (Assuming that we have entered the value 2 in the standard input)
1
hi 2
Run time error
2
What will be the output of the following C code?
h e
e l
h h
e e
What will be the output of the following C code?
Nothing
0
Compile time error
Junkvalue
What is the Output ?
21
5
13
111
What is the Output ?
3.000
3
3.5
3.500
In C '&' used in 'scanf' represents
For separating input data
Pointer to variable
Memory Location
And operator
What is the Output ?
6 6 2
12 0 3
Runtime Error
Compilation Error
'Continue' statement is used to ?
To stop program execution
To go next line
To Stop Current iteration and start next iteration
To run infinite loop
An Array is initialized with size 20 in c. if first element location is at 1940(memory address), what will the location of 11th element?
(size of int = 2bytes)
1961
1960
1950
1951
what does following code do??
Makes the Given Matrix Symmetric
Transpose the Matrix
Matrix Multiplication
None of this
What is the Output?
prints "Hello World"
prints "Hello World" 5 times in same line
prints "Hello World" 5 times in multiple line
prints "0"
What is the Value of "256>>1"
25
128
257
256
first and second term in geometric progression are 3 and 6 find common ratio?
9
2
3
18
What is (void*)0?
Representation of void pointer
Representation of NULL pointer
Error
Representation of int pointer
What will be the output of the following C code?
2 3
2 garbagevalue
Error
2 4
What is the Average and Worst time complexities of Binary Search Algorithm
O(1) , O(1)
O(log n) , O(log n)
O(1) , O(log n)
O(log n) , O(n)
Average time Complexity of Merge Sort?
O(n log n)
O(n^2)
O(n)
O(log n)
What is Output ?
P
o
Coding Club
oding Club
Which type of pointer is a most convention way of storing raw address in c programming?
Void Pointer
Double Pointer
Null Pointer
Integer Pointer
Among 4 header files, which should be included to use the memory allocation functions like malloc(), calloc(), realloc() and free()?
<string.h>
<memory.h>
<stdlib.h>
Both
<memory.h>
<stdlib.h>
What is the return type of malloc() or calloc()?
int *
int **
void *
void **
What is output?
100
Compilation Error
0
Garbage Valur
What is Output ?
-1
0
1
Compilation Error
In C File is a type of?
int
char *
struct
void
If an error occurs, the function fseek() will returns
-1
NULL
non-zero value
0
What is Output ?
14
13
12
11
What is the output ?
Error
i = 1
i = 16
i = 0
What is output ?
1
6
3
Error
what is Output ?
3 3 1 3 1
3 3 1 3 0
Garbage Values
Error
What is the Output ?
Compilation Error
Runtime Error
False
True
How many times is Hello world printed ?
1
4
2
8
What is output?
print i till 9 and j till 19
print i and j till 19
print i and j till 9
Error
The operators (. , !! , < , = )
Ascending order of precedence is?
. !! < =
< !! = .
= < !! .
= !! < .
What will be the output of the code?
#include
10
15
5
20
How many times the while loop will get executed if a short int is 2 byte wide?
#include
Infinite times
255 times
256 times
254 times
Which of the following errors would be reported by the compiler on compiling the program given below?
#include
There is no break statement in each case.
Expression as in case 3 + 2 is not allowed.
Duplicate case case 5:
No error will be reported.
Point out the error, if any in the program.
#include
Error: No default value is specified
Error: Constant expression required at line case P:
Error: There is no break statement in each case.
No error will be reported.
What will be the output of the program?
#include
3, 4
4, 3
4, 4
Output may vary from compiler to compiler
How many times the program will print "SMTEC" ?
#include
Infinite times
32767 times
65535 times
Till stack overflows
What will be the output of the program?
#include
25
11
Error
Garbage value
What will be the output of the program ?
#include
llo
hello
ello
h
What will be the output of the program?
#include
-2, 3, 1, 1
2, 3, 1, 2
1, 2, 3, 1
3, 3, 1, 2
What will be the output of the program ?
#include
SMTEC
India
India SMTEC
India\0SMTEC
What will be the output of the program ?
#include
JCK
J65K
JAK
JACK
Point out the error, if any in the program.
#include
100
200
Error: L value required for b
Garbage value
Which of the following statements are correct about the program?
#include
Error: Statement missing
Error: Expression syntax
Error: Lvalue required
Error: Rvalue required
What will be the output of the program?
#include
1, 1, 1, 1
1, 1, 0, 1
1, 0, 0, 1
1, 0, 1, 1
Point out the error in the program f(int a, int b) { int a; a = 20; return a; }
Missing parenthesis in return statement
The function should be defined as int f(int a, int b)
Redeclaration of a
None of above
What will be the output of the program ?
#include
Hello
World
Hello World
WorldHello
To scan a and b given below, which of the following scanf() statement will you use?
#include
scanf("%f %f", &a, &b);
scanf("%Lf %Lf", &a, &b);
scanf("%f %Lf", &a, &b);
scanf("%f %lf", &a, &b);
What will be the output of the program?
#include
32
64
0
128
Which of the following is the correct order of evaluation for the below expression? z = x + y * z / 4 % 2 - 1
* / % + - =
= * / % + -
/ * % - + =
* % / - + =
What will be the output of the program?
#include
Prints "SMTEC" 5 times
Function main() doesn't calls itself
Infinite loop
Prints "SMTEC"
What will be the output of the program ?
#include
0
1
2
5
What will be the output of the program ?
#include
Hello
HelloWorld
WorldHello
Error
How many times will the for loop execute?
#include
9 times
10 times
11 times
Infinite times
What will be the output of the program ?
#include
2
5
10
15
What will be the output of the program ?
#include
1
2
3
4
What will be the output of the code?
#include
Debug the code
#include
What will be the output of the code?
#include
Fix the error
#include
What will be the output of the code?
#include
Identify the issue with this code and suggest a fix.
#include
What will be the output of the code?
#include
Identify the error with the code
#include
Debug the code
#include
What will be the output?
#include
Identify the error and correct it in the code below: int main() { int* ptr; *ptr = 20; printf("%d\n", *ptr); return 0; }
Find and fix the issue: int main() { int a = 10; int* ptr; ptr = a; printf("%d\n", *ptr); return 0; }
Debug and fix it int main() { int arr[5]; for (int i = 0; i < 5; i++) { printf("%d ", arr[i]); } return 0; }
What will be the output of the program?
#include
200
30
100
500
Which of the following statements are correct about the below C-program?
#include
The printf() function is called 10 times.
The program will produce the output x = 10 y = 10
The ; after the if(x!=y) will NOT produce an error.
The program will not produce output.
What will be the output of the program?
#include
200
30
100
500
Which of the following statements are correct about the function? long fun(int num) { int i; long f=1; for(i=1; i<=num; i++) f = f * i; return f; }
The function calculates the value of 1 raised to power num.
The function calculates the square root of an integer
The function calculates the factorial value of an integer
None of above
Which of the statements is correct about the program?
#include
It prints ASCII value of the binary number present in the first byte of a float variable a.
It prints character equivalent of the binary number present in the first byte of a float variable a.
It will print 3
It will print a garbage value
Will the program compile in Turbo C?
#include
Yes
No
Which of the following statements are correct about an array? 1: The array int num[26]; can store 26 elements. 2: The expression num[1] designates the very first element in the array. 3: It is necessary to initialize the array at the time of declaration. 4: The declaration num[SIZE] is allowed if SIZE is a macro.
1
1,4
2,3
2,4
If char=1, int=4, and float=4 bytes size, What will be the output of the program ?
#include
1, 2, 4
1, 4, 4
2, 2, 4
2, 4, 8
What will be the output of the program ?
#include
Kagpur, Kanpur
Nagpur, Kanpur
Kagpur, anpur
Error
What will be the output of the program ?
#include
12, 12, 12
112, 1, 12
32, 1, 12
-64, 1, 12
What is the output of the program? typedef struct data; { int x; sdata *b; }sdata;
Error: Declaration missing ';'
Error: in typedef
No error
None of above
How many times "IndiaBIX" is get printed?
#include
A.Infinite times
B.11 times
C. 0 times
D. 10 times
What will be the output of the program?
#include
A.1, 2, 0, 1
B.-3, 2, 0, 1
C.-2, 3, 0, 1
D.2, 3, 1, 1
What will be the output of the program?
#include
12, 12
7, 7
7, 12
12, 7
Will the following program print the message infinite number of times?
#include
Yes
No
If the size of integer is 4bytes, What will be the output of the program?
#include
A.10, 2, 4
B.20, 4, 4
C.16, 2, 2
D.20, 2, 2
What will be the output of the program ?
#include
10
20
Error: Non portable pointer conversion
Error: cannot use static for function parameters
What will be the output of the program if the array begins at address 65486?
#include
A.65486, 65488
B.65486, 65486
C.65486, 65490
D.65486, 65487
What will be the output of the program?
#include
15, 50
15, 15
10, 10
5, 5
What will be the output of the program?
#include
0 1 2 3 4
1 2 3 4 5
0 1 2 3 4 5
5
What will be the output of the program?
#include
1, 2
2, 3
1, 3
0, 0
What will be the output of the program?
#include
0 1 2
1 2 3
0 1 2 3
3
Which of the following statements is true about the program?
#include
It prints 3
It prints 2
It prints 5
It prints 1
What will be the output of the program?
#include
True
False
What will be the output of the program?
#include
1, 2
2, 3
1, 3
0, 0
