WorksheetsC Programming Unit-1 Test-2
Total questions: 20
Worksheet time: 29mins
Which of the following is not a valid C variable name?
int number;
float rate;
int variable_count;
int $main;
Which of the following is true for variable names in C?
They can contain alphanumeric characters as well as special characters
It is not an error to declare a variable to be one of the keywords(like goto, static)
Variable names cannot start with a digit
Variable can be of any length
What is short int in C programming?
The basic data type of C
Qualifier
Short is the qualifier and int is the basic data type
All of the mentioned
Which of the following typecasting is accepted by C language?
Widening conversions
Narrowing conversions
Widening & Narrowing conversions
None of the mentioned
Which of the following is NOT possible with any 2 operators in C?
Different precedence, same associativity
Different precedence, different associativity
Same precedence, different associativity
All of the mentioned
Property which allows to produce different executable for different platforms in C is called?
File inclusion
Selective inclusion
Conditional compilation
Recursive macros
What will be the output of the following C code?
int y = 10000;
int y = 34;
printf("Hello World! %d\n", y);
Hello World! 34
Hello World! 10000
Hello World! followed by a junk value
Compile time error
What will be the output of the following C code?
signed char chr;
chr = 128;
printf("%d\n", chr);
128
-128
Depends on the compiler
None
What will be the output of the following C code? (Initial values: x= 7, y = 8)
float x;
int y;
printf("enter two numbers \n", x);
scanf("%f %f", &x, &y);
printf("%f, %d", x, y);
7.000000, 8
Run time error
7.000000, junkvalue
Varies
What is the range of values that can be stored by int datatype in C?
-(2^31) to (2^31) - 1.
-256 to 255
-(2^63) to (2^63)-1
0 to (2^31)-1
Which of the following is an exit controlled loop?
while
for
do-while
switch
What will be the result of the following code snippet?
char ch[10] = "abcdefghij";
int ans = 0;
for(int i = 0; i < 10; i++) {
ans += (ch[i] - 'a'); }
printf("%d", ans);
45
36
20
100
What will be the output of the following code snippet?
int ch = 2;
switch(ch) {
case 1: printf("1 ");
case 2: printf("2 ");
case 3: printf("3 ");
default: printf("None"); }
1 2 3 None
2
2 3 None
None
What will be the output of the following code snippet?
int x = 1,
y = 2;
printf(x > y ? "Greater" : x == y ? "Equal" : "Lesser");
Greater
Lesser
Equal
None
What will be the output of the following code snippet?
printf("%d ", 9 / 2);
printf("%f", 9.0 / 2);
4 4.5000
4 4.000
4.5000 4.5000
4 4
What will be the output of the following code snippet?
int x = 2;
printf("%d", (x << 1) + (x >> 1));
5
4
2
1
Determine the output of the C code mentioned below:
float q = ‘a’;
printf(“%f”, q);
run time error
a
97.000000
a.0000000
Which bitwise operator is suitable for turning 'off' and 'on' a particular bit in a number?
&& &
& |
! !
| &
What will you do to treat the constant 3.14 as a long double?
use 3.14LD
use 3.14L
use 3.14DL
use 3.14LF
float x = 3.6;
int y = ?
printf ("Result = %d\n", y );
Find the expression for y to get result as 4
y = (int)(x + 0.5)
y = int(x + 0.5)
y = (int)x + 0.5
None
