C Programming and Problem Solving Questions and Answers 41 to 50

C Programming and Problem Solving

Questions 41 to 50



41.
Find the output of the following program:
void   main(){
struct xx
{
int x=3;
char name[]="hello";
};
struct xx *s;
printf("%d",s->x);
printf("%s",
s->name);
}
(a)
3 and hello
(b)
3 and h
(c)
Syntax error
(d)
Runtime error
(e)
3 and garbage.
42.
Find the output of the following program:
void main() {
printf("\nab");
printf("\bsi");
prin
tf("\rha");
}
(a)
absiha
(b)
asiha
(c)
siha
(d)
hai
(e)
ha.
43.
Pick the correct output of the following program
#define square(x) x*x
void main()
{
int i;
i = 64/square(4);
printf("%d",i);
}
(a)
Syntax error
(b)
64
(c)
1/4
(d)
4
(e)
1.
44.
What is the correct output for the following piece of code?
#define a 10
void main() {
#define a 50
printf("%d",a);
}
(a)
10
(b)
Syntax error
(c)
Runtime error
(d)
Garbage value
(e)
50.
45.
The output of the following program is
void main() {
printf("%p", main);
}
(a)
Runtime error
(b)
Syntax error
(c)
Some address will be printed
(d)
main
(e)
Infinitely executed program.
46.
What is the output of the following code part?
enum colors {BLACK,BLUE,GREEN}
void     main()  {
printf("%dà%dà%d",BLACK,BLUE,GREEN);
}
(a)
0à1à2
(b)
1à2à3
(c)
Syntax error
(d)
–1à0à1
(e)
BLACKàBLUEàGREEN.
47.
The output of the following program is
#define f(g,g2) g##g2
void main()               {
int var12=100;
printf("%d",f(var,12));
}
(a)
Syntax error
(b)
Runtime error
(c)
g##g2
(d)
100
(e)
10012.
48.
The output of the following program is
void main( )   {
int a[ ] = {10,20,30,40,50},j,*p;
for(j=0; j<5; j++)   {
printf(“%d” ,*a);
a++;
}
p = a;
for(j=0; j<5; j++) {
printf(“%d ” ,*p);
p++;
}
}
(a)
10,20,30,40,50  10,11,12,13,14
(b)
10,20,30,40,50  11,12,13,14,15
(c)
Syntax error
(d)
Runtime error
(e)
10,20,30,40,50 10,20,30,40,50.
49.
The type of the controlling expression of a switch statement cannot be of the type
(a)
Int
(b)
Char
(c)
Short
(d)
Float
(e)
Long.
50.
What's wrong in the following statement, provided k is a variable of type int? 
for (k = 2, k <=12, k++)
(a)
The increment should always be ++k
(b)
The variable must always be the letter i when using a for loop
(c)
There should be a semicolon at the end of the statement
(d)
The variable k can’t be initialized
(e)
The commas should be semicolons.



Answers



41.
C
You can not initialize members in structure declaration.
42.
D
because of these three characters \n - newline   \b - backspace \r - carriage return.
43.
B
the macro call square(4) will substitute 4*4 at macro call, so the expression becomes i = 64/4*4 . Since / and * has equal priority the expression will be evaluated as (64/4)*4 i.e. 16*4 = 64
44.
E
The preprocessor directives can be redefined anywhere in the program. So the most recently assigned value will be taken with the current scope.
45.
C
Function names are just addresses (just like array names are addresses).
main() is also a function. So the address of function main will be printed. %p in printf specifies that the argument is an address. They are printed as hexadecimal numbers.
46.
A
enum members are get assigned with integer values starting from 0, if not explicitly initialized in declaration.
47.
D
## is token pasting operator which simply combines all the parameters of macro into one variable.
48.
C
Error is in line with statement a++. The operand must be an lvalue and may be of any of scalar type for the any operator, array name only when subscripted is an lvalue. Simply array name is a non-modifiable lvalue.
49.
D
According to the syntax of C programming language.
50.
E
In for loop the three statement parts are separated by two semicolons which are missing here.


<< Prev 1...  2...  3...  4...  5...  6...  7...  8...  9...  10...  11... 12...  13...  14...  15...  16...  17...  18...  19...  20...  21...  22...  23...  24...  25...  26...  27...  28...  29...  30...  31...  32...  33...  34...  35...  36...  Next >>


3 comments :