Online C Programming Test - C Programming Test - Random http://www.indiabix.
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
Engineers/MCA Training Embedded/.NET/CATIA/VHDL/J2EE/C&C++ Noida/Lucknow/Gr.Noida/Roorkee(ISO) www.cet
MBA: For Best Placements Start 6 Months before others in JAN and Join the Winter Batch at IIPM www.iipmplacements.c
C Programming Test - Random
C Programming Result & Statistics
1. What will be the output of the program? Marks : 1/20
#include<stdio.h> Total number of questions : 20
int main() Number of answered questions : 2
{
Number of unanswered questions : 18
int x=55;
printf("%d, %d, %d\n", x<=55, x=40, x>=10);
return 0;
} Feedback
Quality of the Test :
A. 1, 40, 1 B. 1, 55, 1
Difficulty of the Test :
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
2. What will be the output of the program?
#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.
Learn more problems on : Expressions
Discuss about this problem : Discuss in Forum
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.
Learn more problems on : C Preprocessor
Discuss about this problem : Discuss in Forum
4. Point out the error in the program
#include<stdio.h>
int main()
{
int a=10;
void f();
a = f();
printf("%d\n", a);
return 0;
}
void f()
{
printf("Hi");
}
A. Error: Not allowed assignment
B. Error: Doesn't print anything
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.
Learn more problems on : Functions
Discuss about this problem : Discuss in Forum
5. A char variable can store either an ASCII character or a Unicode character.
A. True B. False
Answer: Option A
Explanation:
Yes, we can store either an ASCII character or a Unicode character in a char variable.
Learn more problems on : Control Instructions
Discuss about this problem : Discuss in Forum
6. What will be the output of the program?
#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...
C. Error: cannot use control instructions in macro
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.
Step 2: FUN(i<3); becomes,
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.
Hence the output of the program is "IndiaBIX... IndiaBIX..."
Learn more problems on : C Preprocessor
Discuss about this problem : Discuss in Forum
7. What will be the output of the program?
#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
C. Error D. Garbage value
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.
Step 2: a = SQR(b+2); becomes,
=> a = b+2 * b+2; Here SQR(x) is replaced by macro to x*x .
=> a = 3+2 * 3+2;
=> a = 3 + 6 + 2;
=> a = 11;
Step 3: printf("%d\n", a); It prints the value of variable 'a'.
Hence the output of the program is 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
Learn more problems on : C Preprocessor
Discuss about this problem : Discuss in Forum
8. What will be the output of the program?
#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;
}
A. Result= -100.000 B. Result=-25.000
C. Result= 0.000 D. Result=100.000
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.
Step 2: a = 2*(s-u*t)/SQUARE(t); becomes,
=> a = 2 * (10 - 30 * 2) / t * t; Here SQUARE(t) is replaced by macro to t*t .
=> a = 2 * (10 - 30 * 2) / 2 * 2;
=> a = 2 * (10 - 60) / 2 * 2;
=> a = 2 * (-50) / 2 * 2 ;
=> a = 2 * (-25) * 2 ;
=> a = (-50) * 2 ;
=> a = -100;
Step 3: printf("Result=%f", a); It prints the value of variable 'a'.
Hence the output of the program is -100
Learn more problems on : C Preprocessor
Discuss about this problem : Discuss in Forum
9. 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;
}
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
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
10. Point out the error, if any in the program.
#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;
}
A. Error: No default specified
B. Error: Invalid printf statement after switch statement
C. No Error and prints "Case1"
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".
printf("This is c program."); is ignored by the compiler.
Hence there is no error and prints "Case1".
Learn more problems on : Control Instructions
Discuss about this problem : Discuss in Forum
11. Bitwise | can be used to set multiple bits in number.
A. Yes B. No
Answer: Option A
Learn more problems on : Bitwise Operators
Discuss about this problem : Discuss in Forum
12. Can we specify a variable filed width in a scanf() format string?
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
is, the current input field is scanned but not stored.
Learn more problems on : Input / Output
Discuss about this problem : Discuss in Forum
13. What will be the output of the program?
#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
C. Hi Hello D. None of above
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
Learn more problems on : Control Instructions
Discuss about this problem : Discuss in Forum
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;
}
A. Error: Expression syntax B. Error: Lvalue required
C. Error: Rvalue required D. The Code runs successfully
Answer: Option B
Explanation:
if(i % 2 = j % 3) This statement generates "LValue required error". There is no variable on
the left side of the expression to assign (j % 3).
Learn more problems on : Control Instructions
Discuss about this problem : Discuss in Forum
15. Can I increase the size of dynamically allocated array?
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:
Use realloc(variable_name, value);
Learn more problems on : Memory Allocation
Discuss about this problem : Discuss in Forum
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>
int main(int argc, char **argv)
{
int i, j=0;
for(i=0; i<argc; i++)
j = j+atoi(argv[i]);
printf("%d\n", j);
return 0;
}
A. 123 B. 6
C. Error D. "123"
Answer: Option B
Learn more problems on : Command Line Arguments
Discuss about this problem : Discuss in Forum
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>
int main(int argc, char *argv[])
{
printf("%c", *++argv[1]);
return 0;
}
A. r B. f
C. m D. y
Answer: Option A
Learn more problems on : Command Line Arguments
Discuss about this problem : Discuss in Forum
18. What is the output of the program
#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
C. Error D. None of these
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.
Learn more problems on : Declarations and Initializations
Discuss about this problem : Discuss in Forum
19. Which of the following statement obtains the remainder on dividing 5.5 by 1.3 ?
A. rem = (5.5 % 1.3) B. rem = modf(5.5, 1.3)
C. rem = fmod(5.5, 1.3) D. Error: we can't divide
Answer: Option C
Explanation:
fmod(x,y) - Calculates x modulo y, the remainder of x/y.
This function is the same as the modulus operator. But fmod() performs floating point
divisions.
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
Learn more problems on : Floating Point Issues
Discuss about this problem : Discuss in Forum
20. What do the following declaration signify?
char **argv;
A. argv is a pointer to pointer.
B. argv is a pointer to a char pointer.
C. argv is a function pointer.
D. argv is a member of function pointer.
Answer: Option B
Learn more problems on : Complicated Declarations
Discuss about this problem : Discuss in Forum
© 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