C Programming and Problem Solving Questions and Answers 191 to 200

C Programming and Problem Solving

Questions 191 to 200



191.
Identify the wrong statement from the following code block:
int  a;  float b;  char  c; 
(a)
scanf( “%d, %f, %c”, &a, &b, c );
(b)
scanf( “%d %f %c”, &a, &b, &c );
(c)
scanf( “Rs. %d, %f, %c”, &a, &b, &c );
(d)
scanf( “%d, %f, %c”, &a, &b, &c );
(e)
scanf( “%d-%f-%c”, &a, &b, &c );.
192.
What should be the initial values for a, b, c, if 2 has to be printed with the following code?
void main(){
int  a, b, c;
printf( “%d”, ( c>=b>=a ? 1 : 2 ));
}
 (a)
0, 0, 0
(b)
1, 1, 1
(c)
-1, 0, 1
(d)
0, -1, -2
(e)
2, 2, 2
193.
If suppose a variable ‘a’ is initialized as int a=0xff, then what will be output for the below code?
( a << 4 >> 12 )? printf(“Humaira”) : printf( “Iram” );
(a)
Syntax Error
(b)
Logical Error
(c)
Humaira
(d)
Iram
(e)
No output at all.
194.
What is the value of ‘a’, if the expression is executed as a = ( x=10, x*x );?
(a)
Syntax Error
(b)
Garbage Value
(c)
1
(d)
10
(e)
100.
195.
How many times the ‘for’ loop in the following code will be executed on Turbo C compiler?
void main(){
int i=0;
for(; ++i; )
(a)
0 times
(b)
Infinite times
(c)
The maximum value an integer can have in that machine
(d)
One time
(e)
The program will give an syntax error.
196.
Consider the following code:
unsigned char c;
for( c=0; c!=256; c+2)
printf(“%d”, c);
How many times the loop will be executed?
(a)
127
(b)
128
(c)
256
(d)
Infinitely
(e)
Zero.
197.
What is the output of the following code?
void main() {
int i=0;
switch( i ){
case 0: i++;
case 1: i+++2;
case 2: ++i;
}print( “%d”, i++ );
}
(a)
1
(b)
2
(c)
3
(d)
4
(e)
5.
198.
Identify the correct statement from the following statements.
(a)
typedef int Integer
(b)
typedef int Integer;
(c)
typedef int=Integer
(d)
typedef int=Integer;
(e)
typedef Integer int;.
199.
How is a variable accessed from another file?
(a)
The global variable is referenced via the pointer specifier
(b)
The global variable is referenced via the extern specifier
(c)
The global variable is referenced via the auto specifier
(d)
The global variable is referenced via the global specifier
(e)
Can’t be accessed at all in C.
200.
The address of the starting element of an array is
(a)
Represented by subscripted variable of the starting element
(b)
Can’t be specified
(c)
Represented by the array name
(d)
Not used by the compiler
(e)
Represented by the size of the array.



Answers



191.
Answer : (a)
Reason  :       For character variable ‘c’ the ‘&’ is missing in scanf() function.
192.
Answer : (e)
Reason  :       These are the possible values with which the condition becomes false and 2 will be printed. Also the execution for c >= b >= a is left toright.
193.
Answer : (d)
Reason  :       The execution of a << 4 >> 12 is left to right. First a becomes 255 and then becomes 0, and hence the outcome of the expression is false. So “Iram” only will be printed.
194.
Answer : (e)
Reason  :       The outcome of comma separated expression in round brackets is always the right most expression, hence it is 10*10 which is 100.
195.
Answer : (c)
Reason  :       Because i will be incremented up to the maximum value an integer can have, then it becomes -1 and in next iteration becomes 0 which caises the for loop to be terminated.
196.
Answer : (d)
Reason  :       What so for, the value of c is not incremented here at all c+2 is not for incrementing c by 2. Hence always the condition in for loop remains true always.
197.
Answer : (c)
Reason  :       First i is incremented by one as ( i++ in first case), then again incremented in second case and one more time in next case.
198.
Answer : (a)
Reason  :       Others according to the syntax rules of C are wrong and invalid.
199.
Answer : (b)
Reason  :       If a global variable in referenced via extern in a new file then only we can access that variable in the file. Other variables can never be accessed.
200.
Answer : (c)
Reason  :       Because the address of the array is same as the address of the first element of the array.


<< 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 >>



No comments :

What you think about these Questions and Answers ? Let me know in comments.

Post a Comment