Loading Test...
Instruction:
Total number of questions : 20 .
Time alloted : 30 minutes.
Each question carry 1 mark, no negative marks.
1.
What will be the output of the program?
#include<stdio.h>
int main()
{
static int a[20];
int i = 0;
a[i] = i ;
printf("%d, %d, %d\n", a[0], a[1], i);
return 0;
}
Answer: Option C
Explanation:
Step 1 : static int a[20]; here variable a is declared as an integer type and static . If a variable is declared as static and it will ne automatically initialized to value '0'(zero).
Step 2 : int i = 0; here vaiable i is declared as an integer type and initialized to '0'(zero).
Step 3 : a[i] = i ; becomes a[0] = 0;
Step 4 : printf("%d, %d, %d\n", a[0], a[1], i); Here a[0] = 0, a[1] = 0(because all staic variables are initialized to '0') and i = 0.
Step 4 : Hence the output is "0, 0, 0".
Learn more problems on : Expressions
Discuss about this problem : Discuss in Forum
2.
Will the following program print the message infinite number of times?
#include<stdio.h>
#define INFINITELOOP while(1)
int main()
{
INFINITELOOP
printf("IndiaBIX");
return 0;
}
Answer: Option A
Explanation:
Yes, the program prints "IndiaBIX" and runs infinitely.
The macro INFINITELOOP while(1) replaces the text 'INFINITELOOP' by 'while(1)'
In the main function, while(1) satisfies the while condition and it prints "IndiaBIX". Then it comes to while(1) and the loop runs infinitely.
Learn more problems on : C Preprocessor
Discuss about this problem : Discuss in Forum
3.
When we dynamically allocate memory is there any way to free memory during run time?
4.
Can I increase the size of dynamically allocated array?
5.
What will be the output of the program?
#include<stdio.h>
#define CUBE(x) (x*x*x)
int main()
{
int a, b=3;
a = CUBE(b++);
printf("%d, %d\n", a, b);
return 0;
}
Answer: Option C
Explanation:
The macro function CUBE(x) (x*x*x) calculates the cubic value of given number(Eg: 103 .)
Step 1 : int a, b=3; The variable a and b are declared as an integer type and varaible b id initialized to 3.
Step 2 : a = CUBE(b++); becomes
=> a = b++ * b++ * b++;
=> a = 3 * 3 * 3; Here we are using post-increement operator, so the 3 is not increemented in this statement.
=> a = 27; Here, 27 is store in the variable a . By the way, the value of variable b is increemented by 3. (ie: i=6)
Step 3 : printf("%d, %d\n", a, b); It prints the value of variable a and b .
Hence the output of the program is 27, 6.
Learn more problems on : C Preprocessor
Discuss about this problem : Discuss in Forum
6.
Even if integer/float arguments are supplied at command prompt they are treated as strings.
7.
Are the expressions arr and &arr same for an array of 10 integers?
Answer: Option B
Explanation:
Both mean two different things.
arr gives the address of the first
int , whereas the
&arr gives the address of array of ints.
Learn more problems on : Arrays
Discuss about this problem : Discuss in Forum
8.
It is necessary to call the macro va_end if va_start is called in the function.
9.
What will be the output of the program?
#include<stdio.h>
void fun(int);
typedef int (*pf) (int, int);
int proc(pf, int, int);
int main()
{
int a=3;
fun(a);
return 0;
}
void fun(int n)
{
if(n > 0)
{
fun(--n);
printf("%d,", n);
fun(--n);
}
}
A.
0, 2, 1, 0
B.
1, 1, 2, 0
C.
0, 1, 0, 2
D.
0, 1, 2, 0
10.
Point out the error, if any in the program.
#include<stdio.h>
int main()
{
int a = 10, b;
a >=5 ? b=100: b=200;
printf("%d\n", b);
return 0;
}
Answer: Option C
Explanation:
Variable b is not assigned.
It should be like: b = a >= 5 ? 100 : 200;
Learn more problems on : Control Instructions
Discuss about this problem : Discuss in Forum
11.
In the following code what is 'P'?
typedef char *charp;
const charp P;
12.
typedef 's have the advantage that they obey scope rules, that is they can be declared local to a function or a block whereas #define 's always have a global effect.
13.
What will be the output of the program ?
#include<stdio.h>
int main()
{
static char mess[6][30] = {"Don't walk in front of me...",
"I may not follow;",
"Don't walk behind me...",
"Just walk beside me...",
"And be my friend." };
printf("%c, %c\n", *(mess[2]+9), *(*(mess+2)+9));
return 0;
}
14.
Can we use a switch statement to switch on strings?
Answer: Option B
Explanation:
The cases in a
switch must either have integer constants or constant expressions.
Learn more problems on : Control Instructions
Discuss about this problem : Discuss in Forum
15.
What will be the output of the program?
#include<stdio.h>
#include<stdlib.h>
union employee
{
char name[15];
int age;
float salary;
};
const union employee e1;
int main()
{
strcpy(e1.name, "K");
printf("%s %d %f", e1.name, e1.age, e1.salary);
return 0;
}
Answer: Option D
Explanation:
The output will be (in 16-bit platform DOS):
K 75 0.000000
Learn more problems on : Const
Discuss about this problem : Discuss in Forum
16.
What will be the output of the program?
#include<stdio.h>
int main()
{
int y=128;
const int x=y;
printf("%d\n", x);
return 0;
}
Answer: Option A
Explanation:
Step 1 : int y=128; The variable 'y' is declared as an integer type and initialized to value "128".
Step 2 : const int x=y; The constant variable 'x' is declared as an integer and it is initialized with the variable 'y' value.
Step 3 : printf("%d\n", x); It prints the value of variable 'x' .
Hence the output of the program is "128"
Learn more problems on : Const
Discuss about this problem : Discuss in Forum
17.
Bitwise can be used to generate a random number.
18.
What will be the output of the program ?
#include<stdio.h>
int main()
{
int a=250;
printf("%1d\n", a);
return 0;
}
Answer: Option D
Explanation:
int a=250; The variable a is declared as an integer type and initialized to value 250.
printf("%1d\n", a); It prints the value of variable a .
Hence the output of the program is 250.
Learn more problems on : Input / Output
Discuss about this problem : Discuss in Forum
19.
What will be the output of the program ?
#include<stdio.h>
void fun(void *p);
int i;
int main()
{
void *vptr;
vptr = &i;
fun(vptr);
return 0;
}
void fun(void *p)
{
int **q;
q = (int**)&p;
printf("%d\n", **q);
}
20.
What will be the output of the program ?
#include<stdio.h>
int main()
{
char str[] = "peace";
char *s = str;
printf("%s\n", s++ +3);
return 0;
}
Submit your test now to view the Results and Statistics with answer explanation.
Note:
Click the 'Submit Test' button given in the bottom of this page to Submit your answers.
Test will be submitted automatically if the time expired.
Don't refresh the page.
Marks : [XX/XX]
Total number of questions
:
[TQ]
Number of answered questions
:
[AQ]
Number of unanswered questions
:
[UQ]