NEW
Font size
WorksheetsC Programming Quiz
Total questions: 20
Worksheet time: 10mins
what is output of this code? #include int main() { printf("%c ", 5["GeeksQuiz"]); return 0; }
Compile-time error
Runtime error
Q
s
Which of the following is true
gets() can read a string with newline characters but a normal scanf() with %s can not.
gets() can read a string with spaces but a normal scanf() with %s can not.
gets() can always replace scanf() without any additional code.
None of the above
Which of the following functions from “stdio.h” can be used in place of printf()?
fputs() with FILE stream as stdout.
fprintf() with FILE stream as stdout.
fwrite() with FILE stream as stdout.
All of the above three - a, b and c.
In “stdio.h”, there’s no other equivalent function of printf().
Which of the following is not a valid declaration in C?
3 and 4
short int x;
short x;
unsigned short x;
signed short x;
In C, sizes of an integer and a pointer must be same.
True
False
Suppose a C program has floating constant 1.414, what's the best way to convert this as "float" data type?
(float)1.414
float(1.414)
1.414f or 1.414F
1.414 itself of "float" data type i.e. nothing else required.
What is output? #include int main(void) { int a = 1; int b = 0; b = a++ + a++; printf("%d %d",a,b); return 0; }
3 6
Compiler Dependent
3 4
3 3
In C, two integers can be swapped using minimum
0 extra variable
1 extra variable
2 extra variable
4 extra variable
Which of the following operators cannot be overloaded in C/C++ ?
Bitwise right shift assignment
Address of
Indirection
Structure reference
Discuss it
What is the output of code? #include int main() { printf("%d", printf("%d", 1234)); return 0; }
12344
12341
11234
41234
What is the return type of getchar()?
int
char
unsigned char
float
What is the output of code? #include int main() { if (sizeof(int) > -1) printf("Yes"); else printf("No"); return 0; }
Yes
No
Compiler Error
Runtime Error
What is the output? #include "stdio.h" int main() { int a = 10; int b = 15; printf("=%d",(a+1),(b=a+2)); printf(" %d=",b); return 0; }
=11 15=
=11 12=
Compiler Error due to (b=a+2) in the first printf().
No compile error but output would be =11 X= where X would depend on compiler implementation.
#include int main() { int x = 128; printf("\n%d", 1 + x++); return 0; }
128
129
130
131
#include int main() { float x = 0.1; if ( x == 0.1 ) printf("IF"); else if (x == 0.1f) printf("ELSE IF"); else printf("ELSE"); }
ELSE IF
IF
ELSE
#include int main() { short a = 320; char * ptr; ptr = (char * ) & a; printf("%d", * ptr); return 0; }
1
320
64
Compilation error
#include int main() { static int i=5; if (--i){ printf("%d ",i); main(); } }
4 3 2 1
1 2 3 4
4 4 4 4
0 0 0 0
#include int main() { int x = 5; int * const ptr = &x; ++(*ptr); printf("%d", x); return 0; }
Compiler Error
Runtime Error
6
5
#include int main() { int x = 10; static int y = x; if(x == y) printf("Equal"); else if(x > y) printf("Greater"); else printf("Less"); return 0; }
Compiler Error
Equal
Greater
Less
What is output of following code ?
// C program to demonstrate shallow copy
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
struct test
{
char *str;
};
int main()
{
struct test st1, st2;
st1.str = (char )malloc(sizeof(char) 20);
strcpy(st1.str, "GeeksforGeeks");
st2 = st1;
st1.str[0] = 'X';
st1.str[1] = 'Y';
/* Since copy was shallow, both strings are same */
printf("st1's str = %s\n", st1.str);
printf("st2's str = %s\n", st2.str);
return 0;
}
st1's str = XYeksforGeeks
st2's str = XYeksforGeeks
st1's str = XYeksforGeek
st2's str = XYeksforGeek
st1's str = XYeksforGeeks
//st2's str = XYeksforGeeks
//st1's str = XYeksforGeeks
st2's str = XYeksforGeeks
