C Aptitude Questions
01)
Which header file should you include if you are to develop a function that can accept
variable number of arguments?
a) Vararg.h
b) stdlib.h
c) stdio.h
d) stdarg.h
02)
In a ‘C’ program, constant is defined
a)
before main.
b) after main.
c)
anywhere, but starting on a new line.
d) none of the above.
03)
printf(“%d”.printf(“tim*));
a) result in a syntax error.
b) outputs tim3.
c) output garbage.
d) prints tim and terminates abruptly.
04)
The rule for implict type conversion in ‘C’ is
a) int<unsigned<float<double.
b) unsigned<int<float<double.
c) int<unsigned<double<float.
d) unsigned<int<double<float.
05)
Which of the following statements is correct?
a)
C provides no input-output features.
b)
b) C provides no file access features.
c) provides no features to manipulate composite objects.
d) all of the above.
06)
Integer division in a ‘C’ program results in
a)truncation.
b) rounding.
c) overflow.
d) none of the above.
07)
For ‘C’ programming language,which of the following statements is (are) true ?
a) Constant expression are evaluated at compile time.
b) String constants can be concatenated at compile time.
c) Size of the array should be known at compile time.
d) all of the above.
Answers
08)
In a ‘C’ expression involving || operator, evaluation
a)
will be stopped if one of its components evaluates to false.
b) will be stopped if one of its components evaluates to true.
c) takes place from right to left.
d) takes place from left to right.
09)
Which of the following statements is (are) correct ?
a) enum variables can be assigned new values.
b) enum variables can be compared.
c) enumeration feature does not increase the power of C.
d) all of the above.
10)
Which of the following comments regarding the reading of a string,using scanf (with
option) and gets is true ?
a)
Both can be used interchangeably.
b) scanf is delimited by end of line, while gets is not
c) scanf is delimited by blank , while gets is not.
d) none of the above.
11)
Which of the following comments about the ++ operator is (are) correct?
a)
It is unary operator.
b)
The operand can come before or after the operator.
c)
It can not be applied to an expression.
d)
It associates from the right.
e)
all the above.
12)
When a variable of data type double is converted into float then
a)
rounding takes place.
b)
truncation takes place.
c)
the lower order bits are dropped.
d)
none of the above.
13)
Which of the following C statements is syntactically correct?
a) for();
b) for(;);
c) for(,);
d) for(;;);
14)
Consider for loop in a C program.If the condition is missing
Answers
a)
it is assumed to be present and taken to be false.
b)
it is assumed to be present and taken to be true.
c)
it results in a syntax error.
d)
execution will be terminated.
15)
Which of the following statements about for loop are correct?
a)
index value is retained outside the loop.
b)
index value can be changed from within the loop.
c)
Goto can be used to jump,out of the loop.
d)
All of the above.
16)
Arrays can be initialized provided they are
a)
Automatic.
b)External.
c) Static.
d)Both (2) and (3) above.
17)|
Arrays are passed as arguments to sa function by
a)
value.
b) Reference.
c) both (1) and (2) above.
d) none of the above.
18)
It is necessary to declare the type of a function in the calling program if
a)
the function returns an integer.
b)
the function returns a non-integer value.
c)
the function is not defined in the same file.
d)
none of the above.
19)
The declaration void function 1(int)indicates the function 1 is a function which
a)
has no arguments.
b)
returns nothing.
c)
both(1) and (2) above.
d)
None of the above.
20)
Recursive functions are executed in a
a)
Last in first out order.
b)
First in first out order.
c)
Parallel fashion.
d)
all of the above.
21)
When a function is recursively called,all automatic variables
a)
are initialized during each execution.
b)
are retained from the last execution.
Answers
c)
are maintained in a stack.
d)
none of the above.
22)
A static variable
a)
cannot be initialized.
b)
is initialized once at the commencement of execution and cannot be changed at run
time.
c)
retains its value throughout the file of the program.
d)
is same as an automatic variable but is placed at the head of a program.
23)
An external variable
a)
is globally accessible by all functions
b)
has a declaration “extern” associated with it when declared within a function.
c)
will be initialized to 0 if not initialized.
d)
all of the above.
24)
A “switch” statement is used to
a)
switch between functions in a program.
b)
switch from one variable to another variable.
c)
to choose from multiple possibilities which may arise due to different values of a
single variable.
d)
to use switching variable.
25)
The statement #include<math.h>is written at the top of a program to indicate
a)
the beginning of the program.
b)
the program does heavy mathematical calculations
c)
that certainly information about mathematical library functions are to be included at
the beginning of the program.
d)
none of the above.
26)
What is the output of the following ‘C’ program?
main( )
{
extern int I;
i=20;
printf(“%d”,sizeof(i));
}
a)
2
b)
4
c)
would vary from compiler to compiler.
d)
Error, i underdefined.
Answers
27)
What is the output of the following ‘C’ program?
main( )
{
extern int a;
printf(“\n%d”,a);
}
int a=20;
a)
0
b)
20
c)
Error.
d)
Garbage value.
28)
What is the output of the following ‘C’ program?
main( )
{
extern int fun(float);
int a;
a=fun(3.14);
printf(“%d”,a);
}
int fun(aa);
float aa;
{
return ((int)aa);
}
a)
3.14
b)
3.0
c)
0
d)
Error.
29)
What is the output of the following ‘C’ program?
main( )
{
int a[5]={2,3};
printf(“\n%d %d %d”,a[2],a[3],a[4];
}
a)
Garbage values.
b)
2 3 3
Answers
c)
3 2 2
d)
0 0 0
30)
What is the output of the following ‘C’ program?
main( )
{
Struct emp
{
char name[20];
int age;
flat sal;
};
struct emp e={“Tiger”};
printf(“\n%d%d%f”,e.age,e.sal);
a)
Error.
b)
Garbage value
c)
00.0000000
d)
10.000000
31)
In the following ‘C’ program,find the error,if any?
main( )
{
int i=1;
for(; ;)
{
printf(“%d”,i++);
if(i>10)
break;
}
}
a)
The condition is in the for loop is must.
b)
the two semicolons should be dropped.
c)
the for loop should be replaced by a while loop.
d)
No error.
32)
In the following ‘C’ program,find out the error in the ‘while’ loop,if any ?
main( )
{
int i=1;
Answers
While( )
{
printf(“%d”,i++);
if(i>10)
break;
}
}
a)
the condition in the while loop is a must.
b)
there should be atleast a semicolon in the while( ).
c)
the while loop should be replaced by for loop.
d)
No error.
33)
What is the output of the following ‘C’ program?
main( )
{
int i=2;
printf(“\n%d%d”,++i,++i);
}
a)
3 4
b)
4 3
c)
4 4
d)
output may vary from compiler to compiler.
34)
What is the output of the following ‘C’ program?
main( )
{
int x=10,y=10,z=5,i;
i=x<y<z;
printf(“\n%d”,i);
}
a)
1
b)
0
c)
Error.
d)
5
35)
Consider the following ‘C’ statement.what is the order in which functions are called?
A=f1(23,14)*f2(12/4)+f3();
a)
f1,f2,f3
b)
f3,f2,f1
c)
the order may vary from compiler to compiler.
Answers
d)
None of the above.
36)
In the following ‘C’code in which order the functions would be called?
a= (f1(23,14)*12(12/4))+f3();
a)
f1,f2,f3
b)
f3,f2,f1
c)
The order may vary from compiler to compiler.
d)
None of the above.
37)
What is the output of the following ‘C’ program?
main( )
{
float a=0.7;
if(a<0.7)
printf(“C”);
else
Printf(“C++”);
}
a)
C
b)
C++
c)
Error.
d)
None of the above.
38)
What is the output of the following ‘C’ program?
main( )
{
float a=0.7;
if(a<0.7f)
printf(“C”);
else
printf(“C++”);
}
a)
C
b)C++
b)
Error
d)None of the above.
39)
What is the output of the following ‘C’ program?
main( )
{
Answers
printf(“%f”,sqrt(36.0));
}
a)
6.0
b)
6
c)
6.000000
d)
Some absurd value.
40)
We want to round off x,a float, to an int value.What is the correct way to do so?
a)
y=(int)(x+0.5)
b)
y=int(x+0.5)
c)
y=(int) x+0.5;
d)
y=(int)((int)x+0.5).
41)
What error are you likely to get when you run the following program?
main( )
{
struct emp
{
char name[20];
float sal;
}
struct emp-e[10];
int I;
for(i=0;<=9;i++)
scanf(“%s%f”,e[i].name,&e[i].sal);
a)
Suspicious pointer conversion
b)
Floating pint formats not linked
c)
Cannot use scanf( )for structures.
d)
Strings cannot be nested inside structures.
42)
By default any real number in C is treated as
a)
a float
b)
a double
c)
a long double
d)
Depends upon the memory model that you are using.
43)
What is the output of the following ‘C’ program?
main( )
{
Answers
pritnf(“%d%d%d”,sizeof(3.14f),sizeof(3.14),sizeof(3.14I));
}
a)
4 4 4
b)
4 Garbage value
c)
4 8 10
d)
Error
44) If the binary equivalent of 5.375 in normalized form is 0100 0000 1010 1100 0000 0000
0000,0000 what is the output of the following program ?
main( )
{
float a=5.375;
char *p;
int I;
p=(char *)&a;
for(i=0;i<=3;i++)
Printf(“%02x”,(unsigned char)p[i];);
}
a)
40 AC 00 00
b)
00 CA 00 40
c)
00 00 Ac 40
d)
00 00 CA 04
45)
What error would the following function given on compilation ?
f(int a,int b)
{
int a;
a=20;
return a;
}
a)
Missing parantheses is return statement
b)
The function should be defined as int f(int a, int b)
c)
Redeclaration of a
d)
None of the above.
46)
How many times the following ‘C’ program would print ‘Jamboree’ ?
main( )
{
printf(“\nJamboree”);
Answers