Online C Programming Test - ..
Online C Programming Test - ..
com/online-test/c-programming-test/random
Are You a Fresher? Join Placement Oriented 4 Month IT Course Designed for Fresh Grads NIIT.com/IT-Training
C. 1, 55, 0 D. 1, 1, 1 Comments:
Answer: Option A
Explanation:
Step 1: int x=55; here variable x is declared as an integer type and initialized to '55'.
Step 2: printf("%d, %d, %d\n", x<=55, x=40, x>=10);
here x<=55 returns TRUE hence it prints '1'.
x=40 here x is assigned to 40 Hence it prints '40'.
x>=10 returns TRUE. hence it prints '1'. Take an Another Random Test!
Step 3: Hence the output is "1, 40, 1".
Go to Online Test Page
Learn more problems on : Expressions
Go to Home Page
Discuss about this problem : Discuss in Forum
#include<stdio.h>
int main()
{
int i=2;
int j = i + (1, 2, 3, 4, 5);
printf("%d\n", j);
return 0;
}
A. 4 B. 7
C. 6 D. 5
Answer: Option B
Explanation:
Because, comma operator used in the expression i (1, 2, 3, 4, 5). The comma operator has
left-right associativity. The left operand is always evaluated first, and the result of evaluation
is discarded before the right operand is evaluated. In this expression 5 is the right most
operand, hence after evaluating expression (1, 2, 3, 4, 5) the result is 5, which on adding to i
results into 7.
1 of 8 12/28/2010 4:47 PM
Online C Programming Test - C Programming Test - Random http://www.indiabix.com/online-test/c-programming-test/random
3. The preprocessor can trap simple errors like missing declarations, nested comments or
mismatch of braces.
A. True B. False
Answer: Option B
Explanation:
False, the preprocessor cannot trap the errors, it only replaces the macro with the given
expression. But the compiler will detect errors.
int main()
{
int a=10;
void f();
a = f();
printf("%d\n", a);
return 0;
}
void f()
{
printf("Hi");
}
C. No error
D. None of above
Answer: Option A
Explanation:
The function void f() is not visible to the compiler while going through main() function. So we
have to declare this prototype void f(); before to main() function. This kind of error will not
occur in modern compilers.
A. True B. False
Answer: Option A
Explanation:
Yes, we can store either an ASCII character or a Unicode character in a char variable.
#include<stdio.h>
#define FUN(arg) do\
{\
if(arg)\
printf("IndiaBIX...", "\n");\
}while(--i)
2 of 8 12/28/2010 4:47 PM
Online C Programming Test - C Programming Test - Random http://www.indiabix.com/online-test/c-programming-test/random
int main()
{
int i=2;
FUN(i<3);
return 0;
}
IndiaBIX...
A. IndiaBIX...
IndiaBIX
B. IndiaBIX... IndiaBIX...
D. No output
Answer: Option B
Explanation:
The macro FUN(arg) prints the statement "IndiaBIX..." untill the while condition is satisfied.
Step 1: int i=2; The variable i is declared as an integer type and initialized to 2.
do
{
if(2 < 3)
printf("IndiaBIX...", "\n");
}while(--2)
After the 2 while loops the value of i becomes '0'(zero). Hence the while loop breaks.
#include<stdio.h>
#define SQR(x)(x*x)
int main()
{
int a, b=3;
a = SQR(b+2);
printf("%d\n", a);
return 0;
}
A. 25 B. 11
Answer: Option B
Explanation:
The macro function SQR(x)(x*x) calculate the square of the given number 'x'. (Eg: 102)
Step 1: int a, b=3; Here the variable a, b are declared as an integer type and the variable b
is initialized to 3.
=> a = 3 + 6 + 2;
=> a = 11;
3 of 8 12/28/2010 4:47 PM
Online C Programming Test - C Programming Test - Random http://www.indiabix.com/online-test/c-programming-test/random
#include<stdio.h>
#define SQUARE(x) x*x
int main()
{
float s=10, u=30, t=2, a;
a = 2*(s-u*t)/SQUARE(t);
printf("Result=%f", a);
return 0;
}
Answer: Option A
Explanation:
The macro function SQUARE(x) x*x calculate the square of the given number 'x'. (Eg: 102)
Step 1: float s=10, u=30, t=2, a; Here the variable s, u, t, a are declared as an floating
point type and the variable s, u, t are initialized to 10, 30, 2.
=> a = 2 * (10 - 30 * 2) / 2 * 2;
=> a = 2 * (-50) / 2 * 2 ;
=> a = 2 * (-25) * 2 ;
=> a = (-50) * 2 ;
=> a = -100;
#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;
}
A. 9, 4 B. 27, 4
C. 27, 6 D. Error
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.
4 of 8 12/28/2010 4:47 PM
Online C Programming Test - C Programming Test - Random http://www.indiabix.com/online-test/c-programming-test/random
=> 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)
#include<stdio.h>
int main()
{
int i = 1;
switch(i)
{
printf("This is c program.");
case 1:
printf("Case1");
break;
case 2:
printf("Case2");
break;
}
return 0;
}
D. None of above
Answer: Option C
Explanation:
switch(i) becomes switch(1), then the case 1: block is get executed. Hence it prints "Case1".
A. Yes B. No
Answer: Option A
A. Yes B. No
Answer: Option B
Explanation:
In scanf() a * in a format string after a % sign is used for the suppression of assignment. That
5 of 8 12/28/2010 4:47 PM
Online C Programming Test - C Programming Test - Random http://www.indiabix.com/online-test/c-programming-test/random
#include<stdio.h>
int main()
{
float a = 0.7;
if(0.7 > a)
printf("Hi\n");
else
printf("Hello\n");
return 0;
}
A. Hi B. Hello
Answer: Option A
Explanation:
if(0.7 > a) here a is a float variable and 0.7 is a double constant. The double constant 0.7 is
greater than the float variable a. Hence the if condition is satisfied and it prints 'Hi'
Example:
#include<stdio.h>
int main()
{
float a=0.7;
printf("%.10f %.10f\n",0.7, a);
return 0;
}
Output:
0.7000000000 0.6999999881
14. Which of the following statements are correct about the below program?
#include<stdio.h>
int main()
{
int i = 10, j = 15;
if(i % 2 = j % 3)
printf("IndiaBIX\n");
return 0;
}
Answer: Option B
Explanation:
A. Yes B. No
Answer: Option A
6 of 8 12/28/2010 4:47 PM
Online C Programming Test - C Programming Test - Random http://www.indiabix.com/online-test/c-programming-test/random
Explanation:
16. What will be the output of the program (myprog.c) given below if it is executed from the
command line?
cmd> myprog 1 2 3
/* myprog.c */
#include<stdio.h>
#include<stdlib.h>
A. 123 B. 6
C. Error D. "123"
Answer: Option B
17. What will be the output of the program (myprog.c) given below if it is executed from the
command line?
cmd> myprog friday tuesday sunday
/* myprog.c */
#include<stdio.h>
A. r B. f
C. m D. y
Answer: Option A
#include<stdio.h>
int main()
{
int x = 10, y = 20, z = 5, i;
i = x < y < z;
printf("%d\n", i);
return 0;
}
A. 0 B. 1
7 of 8 12/28/2010 4:47 PM
Online C Programming Test - C Programming Test - Random http://www.indiabix.com/online-test/c-programming-test/random
Answer: Option B
Explanation:
Since x < y turns to be TRUE it is replaced by 1. Then 1 < z is compared and to be TRUE. The
1 is assigned to i.
19. Which of the following statement obtains the remainder on dividing 5.5 by 1.3 ?
Answer: Option C
Explanation:
Example:
#include <stdio.h>
#include <math.h>
int main ()
{
printf ("fmod of 5.5 by 1.3 is %lf\n", fmod (5.5, 1.3) );
return 0;
}
Output:
fmod of 5.5 by 1.3 is 0.300000
char **argv;
Answer: Option B
© 2008-2010 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy | Contact us: info@indiabix.com
8 of 8 12/28/2010 4:47 PM