28
1. What will be the output of the program? #include<stdio.h> int main() { typedef float f; static f *fptr; float fval = 90; fptr = &fval; printf("%f\n", *fptr); return 0; } A. 9 B. 0 C. 90.000000 D. 90 Answer: Option C Learn more problems on : Typedef Discuss about this problem : Discuss in Forum 2. Which of the following statements are correct about the program? #include<stdio.h> int main() { unsigned int num; int i; scanf("%u", &num); for(i=0; i<16; i++) { printf("%d", (num<<i & 1<<15)?1:0); } return 0; } A. It prints all even bits from num B. It prints all odd bits from num

c Programming Test Sample (1)

Embed Size (px)

DESCRIPTION

useful forr interviews

Citation preview

1.What will be the output of the program?#include

int main(){ typedef float f; static f *fptr; float fval = 90; fptr = &fval; printf("%f\n", *fptr); return 0;}

A.9

B.0

C.90.000000

D.90

Answer:OptionCLearn more problems on :TypedefDiscuss about this problem :Discuss in Forum

2.Which of the following statements are correct about the program?#include

int main(){ unsigned int num; int i; scanf("%u", &num); for(i=0; ii)].z); return 0;}

A.Nagpur, Chennai, Bangalore

B.agpur, hennai, angalore

C.agpur, Chennai, angalore

D.agpur, Bangalore, Bangalore

Answer:OptionDLearn more problems on :Complicated DeclarationsDiscuss about this problem :Discuss in Forum

8.What will the functionrewind()do?

A.Reposition the file pointer to a character reverse.

B.Reposition the file pointer stream to end of file.

C.Reposition the file pointer to begining of that line.

D.Reposition the file pointer to begining of file.

Answer:OptionDExplanation:rewind()takes the file pointer to the beginning of the file. so that the next I/O operation will take place at the beginning of the file.Example:rewind(FilePointer);Learn more problems on :Library FunctionsDiscuss about this problem :Discuss in Forum

9.What is the purpose offflush()function.

A.flushes all streams and specified streams.

B.flushes only specified stream.

C.flushes input/output buffer.

D.flushes file buffer.

Answer:OptionAExplanation:"fflush()" flush any buffered output associated with filename, which is either a file opened for writing or a shell command for redirecting output to a pipe or coprocess.Example:fflush(FilePointer);fflush(NULL);flushes all streams.Learn more problems on :Library FunctionsDiscuss about this problem :Discuss in Forum

10.What will be the output of the program ?#include

int main(){ int i=4, j=8; printf("%d, %d, %d\n", i|j&j|i, i|j&j|i, i^j); return 0;}

A.12, 12, 12

B.112, 1, 12

C.32, 1, 12

D.-64, 1, 12

Answer:OptionALearn more problems on :Structures, Unions, EnumsDiscuss about this problem :Discuss in Forum

11.Every function must return a value

A.Yes

B.No

Answer:OptionBExplanation:No, If a function return type is declared asvoidit cannot return any value.Learn more problems on :FunctionsDiscuss about this problem :Discuss in Forum

12.In a function tworeturnstatements should never occur.

A.Yes

B.No

Answer:OptionBExplanation:No, In a function tworeturnstatements can occur but not successively.Example:

#include int mul(int, int); /* Function prototype */

int main(){ int a = 0, b = 3, c; c = mul(a, b); printf("c = %d\n", c); return 0;}

/* Two return statements in the mul() function */int mul(int a, int b){ if(a == 0 || b == 0) { return 0; } else { return (a * b); }}Output:c = 0Learn more problems on :FunctionsDiscuss about this problem :Discuss in Forum

13.What will be the output of the program?#includeint main(){ int X=40; { int X=20; printf("%d ", X); } printf("%d\n", X); return 0;}

A.40 40

B.20 40

C.20

D.Error

Answer:OptionBExplanation:In case of a conflict between a local variable and global variable, the local variable gets priority.Learn more problems on :Declarations and InitializationsDiscuss about this problem :Discuss in Forum

14.What would be the equivalent pointer expression for referring the array elementa[i][j][k][l]

A.((((a+i)+j)+k)+l)

B.*(*(*(*(a+i)+j)+k)+l)

C.(((a+i)+j)+k+l)

D.((a+i)+j+k+l)

Answer:OptionBLearn more problems on :PointersDiscuss about this problem :Discuss in Forum

15.Which of the statements is correct about the program?#include

int main(){ int arr[3][3] = {1, 2, 3, 4}; printf("%d\n", *(*(*(arr)))); return 0;}

A.Output: Garbage value

B.Output: 1

C.Output: 3

D.Error: Invalid indirection

Answer:OptionDLearn more problems on :PointersDiscuss about this problem :Discuss in Forum

16.va_listis an array that holds information needed byva_argandva_end

A.True

B.False

Answer:OptionALearn more problems on :Variable Number of ArgumentsDiscuss about this problem :Discuss in Forum

17.Which bitwise operator is suitable for turning off a particular bit in a number?

A.&& operator

B.& operator

C.|| operator

D.! operator

Answer:OptionBLearn more problems on :Bitwise OperatorsDiscuss about this problem :Discuss in Forum

18.Which of the following special symbol allowed in a variable name?

A.* (asterisk)

B.| (pipeline)

C.- (hyphen)

D._ (underscore)

Answer:OptionDExplanation:Variable names in C are made up of letters (upper and lower case) and digits. The underscore character ("_") is also permitted. Names must not begin with a digit.Examplesof valid (but not very descriptive) C variable names:=> foo=> Bar=> BAZ=> foo_bar=> _foo42=> _=> QuUxLearn more problems on :Declarations and InitializationsDiscuss about this problem :Discuss in Forum

19.Point out the error, if any in the program.#includeint 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: Invalidprintfstatement afterswitchstatement

C.No Error and prints "Case1"

D.None of above

Answer:OptionCExplanation:switch(i)becomesswitch(1), then thecase 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 InstructionsDiscuss about this problem :Discuss in Forum

20.The prototypes of all standard library string functions are declared in the filestring.h.

A.Yes

B.No

Answer:OptionAExplanation:string.his the header in the C standard library for the C programming language which contains macro definitions, constants, and declarations of functions and types used not only for string handling but also various memory handling functions.Learn more problems on :Library FunctionsDiscuss about this problem :Discuss in Forum

1.Which of the following statements are correct about the below C-program?#includeint main(){ int x = 10, y = 100%90, i; for(i=1; i5 ? (num 5 ? (num