Upload
zaiba-khan
View
31
Download
0
Embed Size (px)
DESCRIPTION
c language questions
Citation preview
NO. QUESTION A
1
10
2
During editing
3
strinit()
4
-1
5
How will you print \n on the screen? printf("\n");
6
strnstr()
7
strchr()
8
printf();
What will be output of the following program?#include<stdio.h>int main(){int x;x=10,20,30;printf("%d",x);return 0;}
In which stage the following code #include<stdio.h> gets replaced by the contents of the file stdio.h
Which of the following function sets first n characters of a string to a given character?
If the two strings are identical, then strcmp() function returns
The library function used to find the last occurrence of a character in a string is
Which of the following function is used to find the first occurrence of a given string in another string?
Which of the following function is more appropriate for reading in a multi-word string?
9
Hello
10
A
11
6
12
Good Morning
13
abc abc
What will be the output of the program ?#include<stdio.h>#include<string.h>
int main(){ char str1[20] = "Hello", str2[20] = " World"; printf("%s\n", strcpy(str2, strcat(str1, str2))); return 0;}
What will be the output of the program ?#include<stdio.h>
int main(){ char p[] = "%d\n"; p[1] = 'c'; printf(p, 65); return 0;}
What will be the output of the program ?#include<stdio.h>#include<string.h>
int main(){ printf("%d\n", strlen("123456")); return 0;}
What will be the output of the program ?#include<stdio.h>
int main(){ printf(5+"Good Morning\n"); return 0;}
What will be the output of the program If characters 'a', 'b' and 'c' enter are supplied as input?#include<stdio.h>
int main(){ void fun(); fun(); printf("\n"); return 0;}void fun(){ char c; if((c = getchar())!= '\n') fun(); printf("%c", c);}
14
Error
15
16
C
17
ptr is pointer to function
18
t, t
What will be the output of the program ?#include<stdio.h>
int main(){ printf("India", "BIX\n"); return 0;}
What will be the output of the program ?#include<stdio.h>
int main(){ char *names[] = { "Suresh", "Siva", "Sona", "Baiju", "Ritu"}; int i; char *t; t = names[3]; names[3] = names[4]; names[4] = t; for(i=0; i<=4; i++) printf("%s,", names[i]); return 0;} Suresh, Siva, Sona, Baiju,
RituWhat will be output of the following program? #include<stdio.h> int main(){ float a=0.7; if(a<0.7){ printf("C"); } else{ printf("C++"); } return 0; }
What is meaning of following declaration? int(*ptr[5])();
What will be the output of the program ?#include<stdio.h>
int main(){ static char mess[6][30] = {"Don't walk in front of me...", "I may not follow;", "Don't walk behind me...", "Just walk beside me...", "And be my friend." };
printf("%c, %c\n", *(mess[2]+9), *(*(mess+2)+9)); return 0;}
19
What are the different types of real data type in C ? float, double
20
#include<conio.h>
21
The binary equivalent of 5.375 is 101.101110111
22
What will you do to treat the constant 3.14 as a float? use float(3.14f)
23
C
24
6
Which statement will you add in the following program to work it correctly?#include<stdio.h>int main(){ printf("%f\n", log(36.0)); return 0;}
What will be the output of the program?#include<stdio.h>int main(){ float a=0.7; if(a < 0.7) printf("C\n"); else printf("C++\n"); return 0;}
What will be the output of the program?#include<stdio.h>#include<math.h>int main(){ printf("%f\n", sqrt(36.0)); return 0;}
25
4, 4, 4
26
2.000000, 1.000000
27
What is (void*)0?
28
Can you combine the following two statements into one? char p = *malloc(100);
29
In which header file is the NULL macro defined? stdio.h
30
.
31
((((a+i)+j)+k)+l)
32A pointer is
. What will be the output of the program?#include<stdio.h>#include<math.h>int main(){ printf("%d, %d, %d\n", sizeof(3.14f), sizeof(3.14), sizeof(3.14l)); return 0;}
What will be the output of the program?#include<stdio.h>#include<math.h>int main(){ float n=1.54; printf("%f, %f\n", ceil(n), floor(n)); return 0;}
Representation of NULL pointer
. If a variable is a pointer to a structure, then which of the following operator is used to access data members of the structure through the pointer variable?
What would be the equivalent pointer expression for referring the array elementa[i][j][k][l]
A keyword used to create variables
33
*
34
ink
35
30
36
x=31, y=502, z=502
The operator used to get value at address stored in a pointer variable is
What will be the output of the program ?#include<stdio.h>
int main(){ static char *s[] = {"black", "white", "pink", "violet"}; char **ptr[] = {s+3, s+2, s+1, s}, ***p; p = ptr; ++p; printf("%s", **p+1); return 0;}
. What will be the output of the program ?#include<stdio.h>
int main(){ int i=3, *j, k; j = &i; printf("%d\n", i**j*i+*j); return 0;}What will be the output of the program ?#include<stdio.h>
int main(){ int x=30, *y, *z; y=&x; /* Assume address of x is 500 and integer is 4 byte size */ z=y; *y++=*z++; x++; printf("x=%d, y=%d, z=%d\n", x, y, z); return 0;}
37
Error
38
10, 2, 4
39
40
float **fun(float***);
41
What will be the output of the program ?#include<stdio.h>
int main(){ char *str; str = "%s"; printf(str, "K\n"); return 0;}
. If the size of integer is 4bytes, What will be the output of the program?#include<stdio.h>
int main(){ int arr[] = {12, 13, 14, 15, 16}; printf("%d, %d, %d\n", sizeof(arr), sizeof(*arr), sizeof(arr[0])); return 0;}
Point out the compile time error in the program given below.#include<stdio.h>
int main(){ int *x; *x=100; return 0;} Error: invalid assignment
for x
Which of the following statements correctly declare a function that receives a pointer to pointer to a pointer to a float and returns a pointer to a pointer to a pointer to a pointer to a float?
Which of the following statements correct about k used in the below statement?char ****k; k is a pointer to a pointer
to a pointer to a char
42
Output: Garbage value
43
How will you free the allocated memory ? remove(var-name);
44
45
-1, 0, 1, 2, 3, 4
46
-1, 0, 1, 2, 3, 4
47
What will the function rewind() do?
Which of the statements is correct about the program?#include<stdio.h>
int main(){ int arr[3][3] = {1, 2, 3, 4}; printf("%d\n", *(*(*(arr)))); return 0;}
What is the similarity between a structure, union and enumeration?
All of them let you define new values
What will be the output of the program ?#include<stdio.h>
int main(){ enum days {MON=-1, TUE, WED=6, THU, FRI, SAT}; printf("%d, %d, %d, %d, %d, %d\n", MON, TUE, WED, THU, FRI, SAT); return 0;}
What will be the output of the program ?#include<stdio.h>
int main(){ enum days {MON=-1, TUE, WED=6, THU, FRI, SAT}; printf("%d, %d, %d, %d, %d, %d\n", ++MON, TUE, WED, THU, FRI, SAT); return 0;}
Reposition the file pointer to a character reverse
48
conio.h
49
conio.h
50
strnchar()
51What is stderr ? standard error
52
What is the purpose of fflush() function
53
returns a random number
54
Input/output function prototypes and macros are defined in which header file?
Input/output function prototypes and macros are defined in which header file?
Which standard library function will you use to find the last occurance of a character in a string in C?
flushes all streams and specified streams
What will the function randomize() do in Turbo C under DOS?
What will be the output of the program?#include<stdio.h>
int main(){ int i; i = printf("How r u\n"); i = printf("%d\n", i); printf("%d\n", i); return 0;}
How r u72
55
1
56
What will function gcvt() do?
57
aaaa
58
What will be the output of the program?#include<stdio.h>
int main(){ int i; i = scanf("%d %d", &i, &i); printf("%d\n", i); return 0;}
Convert vector to integer value
What will be the output of the program?#include<stdio.h>
int main(){ int i; char c; for(i=1; i<=5; i++) { scanf("%c", &c); /* given input is 'a' */ printf("%c", c); ungetc(c, stdin); } return 0;}
Point out the error in the following program.#include<stdio.h>
int main(){ fprintf("IndiaBIX"); printf("%.ef", 2.0); return 0;} Error: unknown value in
printf() statement
59
Error: in Array declaration
60
61
Point out the error in the following program.#include<stdio.h>
int main(){ char str[] = "IndiaBIX"; printf("%.#s %2s", str, str); return 0;}
Point out the error in the following program.#include<stdio.h>
int main(){ fprintf("IndiaBIX"); printf("%.ef", 2.0); return 0;} Error: unknown value in
printf() statement
Point out the error in the following program.#include<stdio.h>
int main(){ fprintf("IndiaBIX"); printf("%.ef", 2.0); return 0;} Error: unknown value in
printf() statement.
62
Infinite times
63
Which of the following is not logical operator? &
64
65
Character
66
0, 1, 2, 3, 4, 5
How many times the while loop will get executed if a short int is 2 byte wide?#include<stdio.h>int main(){ int j=1; while(j <= 255) { printf("%c %d\n", j, j); j++; } return 0;}
In mathematics and computer programming, which is the correct order of mathematical operators ?
Addition, Subtraction, Multiplication, Division
Which of the following cannot be checked in a switch-case statement?
What will be the output of the program?#include<stdio.h>int main(){ int i=0; for(; i<=5; i++); printf("%d", i); return 0;}
67
C-program
68
b = 300 c = 200
69
Infinite loop
What will be the output of the program?#include<stdio.h>int main(){ char str[]="C-program"; int a = 5; printf(a >10?"Ps\n":"%s\n", str); return 0;}
What will be the output of the program?#include<stdio.h>int main(){ int a = 500, b = 100, c; if(!a >= 400) b = 300; c = 200; printf("b = %d c = %d\n", b, c); return 0;}
What will be the output of the program?#include<stdio.h>int main(){ unsigned int i = 65535; /* Assume 2 byte integer*/ while(i++ != 0) printf("%d",++i); printf("\n"); return 0;}
70
x and y are equal
71
1 ... 65535
72
It matters
73
Infinite loop
What will be the output of the program?#include<stdio.h>int main(){ int x = 3; float y = 3.0; if(x == y) printf("x and y are equal"); else printf("x and y are not equal"); return 0;}
What will be the output of the program, if a short int is 2 bytes wide?#include<stdio.h>int main(){ short int i = 0; for(i<=5 && i>=-1; ++i; i>0) printf("%u,", i); return 0;}
What will be the output of the program?#include<stdio.h>int main(){ char ch; if(ch = printf("")) printf("It matters\n"); else printf("It doesn't matters\n"); return 0;}
What will be the output of the program?#include<stdio.h>int main(){ unsigned int i = 65536; /* Assume 2 byte integer*/ while(i != 0) printf("%d",++i); printf("\n"); return 0;}
74
Hi
75
0, 1, 3
76
200
77
300, 300, 200
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;}
What will be the output of the program?#include<stdio.h>int main(){ int a=0, b=1, c=3; *((a) ? &b : &a) = a ? b : c; printf("%d, %d, %d\n", a, b, c); return 0;}
What will be the output of the program?#include<stdio.h>int main(){ int k, num = 30; k = (num < 10) ? 100 : 200; printf("%d\n", num); return 0;}
What will be the output of the program?#include<stdio.h>int main(){ int a = 300, b, c; if(a >= 400) b = 300; c = 200; printf("%d, %d, %d\n", a, b, c); return 0;}
78
79
x=2, y=1, z=1
80
What will be the output of the program?#include<stdio.h>int main(){ int x=1, y=1; for(; y; printf("%d %d\n", x, y)) { y = x++ <= 5; } printf("\n"); return 0;}
2 13 14 15 16 17 0
What will be the output of the program?#include<stdio.h>int main(){ int x, y, z; x=y=z=1; z = ++x || ++y && ++z; printf("x=%d, y=%d, z=%d\n", x, y, z); return 0;}
Point out the error, if any in the program.#include<stdio.h>int main(){ int a = 10; switch(a) { } printf("This is c program."); return 0;} Error: No case statement
specified
81
82
83
Output: Have a nice day
Point out the error, if any in the while loop.#include<stdio.h>int main(){ int i=1; while() { printf("%d\n", i++); if(i>10) break; } return 0;}
There should be a condition in the while loop
Point out the error in the program
f(int a, int b){ int a; a = 20; return a;}
Missing parenthesis in return statement
Which of the following statements are correct about the below program?#include<stdio.h>int main(){ int i = 10, j = 20; if(i = 5) && if(j = 10) printf("Have a nice day"); return 0;}
84
Error: Statement missing
85
86
1,2
Which of the following statements are correct about the program?#include<stdio.h>int main(){ int x = 30, y = 40; if(x == y) printf("x is equal to y\n");
else if(x > y) printf("x is greater than y\n");
else if(x < y) printf("x is less than y\n") return 0;}
Which of the following statements are correct about the below C-program?#include<stdio.h>int main(){ int x = 10, y = 100%90, i; for(i=1; i<10; i++) if(x != y); printf("x = %d y = %d\n", x, y); return 0;} Error: Declaration
terminated incorrectly
Which of the following sentences are correct about a switch loop in a C program?1: switch is useful when we wish to check the value of variable against a particular set of values.2: switch is useful when we wish to check whether a value falls in different ranges.3: Compiler implements a jump table for cases used in switch.4: It is not necessary to use a break in every switch statement.
87
88
89
90
A
91
1
92
It compiles
What will happen if in a C program you assign a value to an array element whose subscript exceeds the size of array?
The element will be set to 0.
What does the following declaration mean?int (*ptr)[10]; ptr is array of pointers to
10 integers
In C, if you pass an array as an argument to a function, what actually gets passed?
Value of elements in array
Which of the following statements mentioning the name of the array begins DOES NOT yield the base address?1: When array name is used with the sizeof operator.2: When array name is operand of the & operator.3: When array name is passed to scanf() function.4: When array name is passed to printf() function.
Which of the following statements are correct about an array?1: The array int num[26]; can store 26 elements.2: The expression num[1] designates the very first element in the array.3: It is necessary to initialize the array at the time of declaration.4: The declaration num[SIZE] is allowed if SIZE is a macro.
What will the SWAP macro in the following program be expanded to on preprocessing? will the code compile?#include<stdio.h>#define SWAP(a, b, c)(c t; t=a, a=b, b=t)int main(){ int x=10, y=20; SWAP(x, y, int); printf("%d %d\n", x, y); return 0;}
93
Compiles and print nothing During editing
94
128 characters
95
What do the 'c' and 'v' in argv stands for?
96
strchr()
97
printf();
98Which of the following is/are storage class Automatic
99NULL Pointer can be used as
100
101
The maximum combined length of the command-line arguments including the spaces between adjacent arguments is
c' means argument control 'v' means argument vector
Which of the following function is used to find the first occurrence of a given string in another string?
Which of the following function is more appropriate for reading in a multi-word string?
To stop indirection in a recursive data structure
The use of “break” Statement to terminate a case in the switch statement
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
B C D SOLUTION ANSWER
20 30 0 A
During linking During execution During preprocessing D
strnset() strset() strcset() B
1 0 YES C
echo "\\n"; printf('\n'); printf("\\n"); D
laststr() strrchr() strstr() C
strrchr() strstr() strnset() C
scanf(); gets(); puts(); C
World Hello World WorldHello C
a c 65 A
12 7 2 A
Good M Morning D
bca Infinite loop cba D
India BIX India BIX C
B
C++ NULL Compilation error A
B
k, k n, k m, f B
Suresh, Siva, Sona, Ritu, Baiju
Suresh, Siva, Baiju, Sona, Ritu
Suresh, Siva, Ritu, Sona, Baiju
ptr is array of pointer to function
ptr is pointer to such function which return type is array
ptr is pointer to array of function
double, long int, float C
#include<math.h> #include<stdlib.h> #include<dos.h> B
101.011 101011 None of above B
use 3.14f use f(3.14) use (f)(3.14) B
C++ Compiler error Non of above A
6 6 C
short int, double, long int
float, double, long double
Error: Prototype sqrt() not found
4, 8, 8 4, 8, 10 4, 8, 12 C
1.500000, 1.500000 1.550000, 2.000000 1.000000, 2.000000 A
Error None of above A
C
stddef.h stdio.h and stddef.h math.h C
& * -> D
*(*(*(*(a+i)+j)+k)+l) (((a+i)+j)+k+l) ((a+i)+j+k+l) B
All of the above C
Representation of void pointer
char *p = (char) malloc(100);
char *p = (char*)malloc(100);
char *p = (char *)(malloc*)(100);
A variable that stores address of an instruction
A variable that stores address of other variable
& && || A
ack ite let A
27 9 3 A
x=31, y=500, z=500 x=31, y=498, z=498 x=31, y=504, z=504 D
No output K %s C
20, 4, 4 16, 2, 2 20, 2, 2 B
No error None of above C
float *fun(float**); float fun(float***); float ****fun(float***); D
B
Error: suspicious pointer conversion
k is a pointer to a pointer to a pointer to a pointer to a char
k is a pointer to a char pointer
k is a pointer to a pointer to a char
Output: 1 Output: 3 Error: Invalid indirection D
free(var-name); delete(var-name); dalloc(var-name); B
B
-1, 2, 6, 3, 4, 5 -1, 0, 6, 2, 3, 4 -1, 0, 6, 7, 8, 9 D
Error 0, 1, 6, 3, 4, 5 0, 0, 6, 7, 8, 9 B
D
All of them let you define new data types
All of them let you define new pointers
All of them let you define new structures
Reposition the file pointer stream to end of file.
Reposition the file pointer to begining of that line.
Reposition the file pointer to begining of file.
stdlib.h stdio.h dos.h C
stdlib.h stdio.h dos.h C
strchar() strrchar() strrchr() D
standard error types C
flushes file buffer. A
C
B
standard error streams
standard error definitions
flushes only specified stream
flushes input/output buffer
returns a random number generator in the specified range.
returns a random number generator with a random value based on time
return a random number with a given seed value
How r u82
How r u11 Error: cannot assign
printf to variable
2 Garbage value B
B
aaaaa Garbage value. B
No error and prints "2.0" B
Error: cannot assign scanf to variable
Convert floating-point number to a string
Convert 2D array in to 1D array.
Covert multi Dimensional array to 1D array
Error in ungetc statement
Error: in fprintf() statement
No error and prints "IndiaBIX"
No error D
No error and prints "2.0" B
No error and prints "2.0" B
Error: printf statement
Error: unspecified character in printf
Error: in fprintf() statement
No error and prints "IndiaBIX"
Error: in fprintf() statement
No error and prints "IndiaBIX"
255 times 256 times 254 times B
&& || ! A
B
Integer Float enum C
5 1, 2, 3, 4 6 D
Division, Multiplication, Addition, Subtraction
Multiplication, Addition, Division, Subtraction
Addition, Division, Modulus, Subtraction
Ps Error None of above A
b = 100 c = garbage b = 300 c = garbage b = 100 c = 200 D
0 1 2 ... 65535 No output A0 1 2 ... 32767 - 32766 -32765 -1 0
x and y are not equal Unpredictable No output A
No output 0, 1, 2, 3, 4, 5 A
It doesn't matters matters No output B
0 1 2 ... 65535 No output D
Expression syntax error
0 1 2 ... 32767 - 32766 -32765 -1 0
Hello Hi Hello None of above A
1, 2, 3 3, 1, 3 1, 3, 1 C
30 100 500 B
Garbage, 300, 200 300, Garbage, 200 300, 300, Garbage C
A
x=2, y=2, z=1 x=2, y=2, z=2 x=1, y=2, z=1 A
No Error C
2 13 14 15 16 1
2 13 14 15 1
2 23 34 45 5
Error: No default specified
Error: infinite loop occurs
No error A
Redeclaration of a None of above C
No output C
There should be at least a semicolon in the while
The while loop should be replaced with for loop.
The function should be defined as int f(int a, int b)
Error: Expression syntax
Error: Undeclared identifier if
Error: Rvalue required A
Error: Syntax error None of above C
1,3,4 2,4 2 B
Error: Expression syntax
Error: Lvalue required
Error: Lvalue required
C
ptr is an pointer to array B
C
A, B B B, D B
1,4 2,3 2,4 B
Not compile C
The compiler would report an error.
The program may crash if some important data gets overwritten.
The array size would appropriately grow.
ptr is a pointer to an array of 10 integers
ptr is an array of 10 integers
First element of the array
Base address of the array
Address of the last element of array
Compiles with an warning
Compiles and print nothing
During linking During execution During preprocessing D
256 characters 67 characters D
C
strrchr() strstr() strnset() C
scanf(); gets(); puts(); C
Satatic Allocated All the above D
As an error value As an sentinel value All the above D
Both A & B Only A C
It may vary from one operating system to another
c' means argument count 'v' means argument vertex
c' means argument count 'v' means argument vector
c' means argument configuration 'v' means argument visibility
to force immediate termination of a loop
NO. QUESTION A
1
Virtual class
2
3
4
5
6
7
Which of the following type of class allows only one object of it to be created?
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
94
95
96
97
98
99
100
B C D
Abstract class Singleton class Friend class
SOLUTION ANSWER
C