You are on page 1of 25

Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1 ? A. B. C. D. rem = 3.14 % 2.

1; rem = modf(3.14, 2.1); rem = fmod(3.14, 2.1); Remainder cannot be obtain in floating point division.

Answer & Explanation

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 3.14/2.1 is %lf\n", fmod (3.14,2.1) ); return 0; }
Output: fmod of 3.14/2.1 is 1.040000 2.

What are the types of linkages? A. C. Internal and External External and None B. D. External, Internal and None Internal

Answer & Explanation

Answer: Option B Explanation: External Linkage-> means global, non-static variables and functions. Internal Linkage-> means static variables and functions with file scope.

None Linkage-> means Local variables. View Answer Workspace Report Discuss in Forum 3.

Which of the following special symbol allowed in a variable name? A. C. * (asterisk) - (hyphen) B. D. | (pipeline) _ (underscore)

Answer & Explanation

Answer: Option D Explanation: 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. Examples of valid (but not very descriptive) C variable names: => foo => Bar => BAZ => foo_bar => _foo42 => _ => QuUx View Answer Workspace Report Discuss in Forum 4.

Is there any difference between following declarations? 1 : extern int fun(); 2 : int fun(); A. B. C. D. Both are identical No difference, except extern int fun(); is probably in another file

int fun(); is overrided with extern int fun();


None of these

Answer & Explanation

Answer: Option B

Explanation:

extern int fun(); declaration in C is to indicate the existence of a global function and it is
defined externally to the current module or in another file.

int fun(); declaration in C is to indicate the existence of a function inside the current module
or in the same file. View Answer Workspace Report Discuss in Forum 5.

How would you round off a value from 1.66 to 2.0? A. C. ceil(1.66) roundup(1.66) B. D. floor(1.66) roundto(1.66)

Answer & Explanation

Answer: Option A Explanation:

/* Example for ceil() and floor() functions: */ #include<stdio.h> #include<math.h> int main() { printf("\n Result : %f" , ceil(1.44) ); printf("\n Result : %f" , ceil(1.66) ); printf("\n Result : %f" , floor(1.44) ); printf("\n Result : %f" , floor(1.66) ); return 0; } // // // // // Output: Result : Result : Result : Result : 2.000000 2.000000 1.000000 1.000000

6.

By default a real number is treated as a A. C. float long double B. D. double far double

Answer & Explanation

Answer: Option B Explanation: In computing, 'real number' often refers to non-complex floating-point numbers. It include both rational numbers, such as 42 and 3/4, and irrational numbers such as pi = 3.14159265... When the accuracy of the floating point number is insufficient, we can use the double to define the number. The double is same as float but with longer precision and takes double space (8 bytes) than float. To extend the precision further we can use long double which occupies 10 bytes of memory space. View Answer Workspace Report Discuss in Forum 7.

Which of the following is not user defined data type? 1:

struct book { char name[10]; float price; int pages; };

2:

long int l = 2.35;

3:

enum day {Sun, Mon, Tue, Wed};

A. C.

1 3

B. D.

2 Both 1 and 2

Answer & Explanation

Answer: Option B Explanation: C data types classification are 1. Primary data types 1. int 2. char 3. float 4. double

5. void 2. Secondary data types (or) User-defined data type 1. Array 2. Pointer 3. Structure 4. Union 5. Enum So, clearly long int l = 2.35; is not User-defined data type. (i.e.long int l = 2.35; is the answer.) View Answer Workspace Report Discuss in Forum 8.

Is the following statement a declaration or definition?

extern int i;
A. C. Declaration Function B. D. Definition Error

Answer & Explanation

Answer: Option A Explanation: Declaring is the way a programmer tells the compiler to expect a particular type, be it a variable, class/struct/union type, a function type (prototype) or a particular object instance. (ie. extern int i) Declaration never reserves any space for the variable or instance in the program's memory; it simply a "hint" to the compiler that a use of the variable or instance is expected in the program. This hinting is technically called "forward reference". View Answer Workspace Report Discuss in Forum 9.

Identify which of the following are declarations 1 : extern int x; 2 : float square ( float x ) { ... } 3 : double pow(double, double); A. C. 1 1 and 3 B. D. 2 3

Answer & Explanation

Answer: Option C Explanation: extern int x; - is an external variable declaration. double pow(double, double); - is a function prototype declaration. Therefore, 1 and 3 are declarations. 2 is definition. View Answer Workspace Report Discuss in Forum 10. In the following program where is the variable a getting defined and where it is getting declared?

#include<stdio.h>
int main() { extern int a; printf("%d\n", a); return 0; } int a=20; A. B. C. D.

extern int a is declaration, int a = 20 is the definition int a = 20 is declaration, extern int a is the definition int a = 20 is definition, a is not defined a is declared, a is not defined

Answer & Explanation

Answer: Option A Explanation: - During declaration we tell the datatype of the Variable. - During definition the value is initialized. When we mention the prototype of a function? A. C. Defining Prototyping B. D. Declaring Calling

Answer & Explanation Answer: Option B

Explanation: A function prototype in C or C++ is a declaration of a function that omits the function body but does specify the function's name, argument types and return type. While a function definition specifies what a function does, a function prototype can be thought of as specifying its interface. 1.

What is the output of the program given below ?

#include<stdio.h>
int main() { enum status { pass, fail, atkt}; enum status stud1, stud2, stud3; stud1 = pass; stud2 = atkt; stud3 = fail; printf("%d, %d, %d\n", stud1, stud2, stud3); return 0; } A. C. 0, 1, 2 0, 2, 1 B. D. 1, 2, 3 1, 3, 2

Answer & Explanation

Answer: Option C Explanation:

enum takes the format like {0,1,2..) so pass=0, fail=1, atkt=2 stud1 = pass (value is 0) stud2 = atkt (value is 2) stud3 = fail (value is 1)
Hence it prints 0, 2, 1 View Answer Workspace Report Discuss in Forum 2.

What will be the output of the program in 16 bit platform (Turbo C under DOS)?

#include<stdio.h>
int main() { extern int i; i = 20; printf("%d\n", sizeof(i));

return 0; } A. B. C. D. 2 4 vary from compiler Linker Error : Undefined symbol 'i'

Answer & Explanation

Answer: Option D Explanation: Linker Error : Undefined symbol 'i' The statement extern int i specifies to the compiler that the memory for 'i' is allocated in some other program and that address will be given to the current program at the time of linking. But linker finds that no other variable of name 'i' is available in any other program with memory space allocated for it. Hence a linker error has occurred. View Answer Workspace Report Discuss in Forum 3.

What is the output of the program?

#include<stdio.h>
int main() { extern int a; printf("%d\n", a); return 0; } int a=20; A. C. 20 Garbage Value B. D. 0 Error

Answer & Explanation

Answer: Option A Explanation:

extern int a; indicates that the variable a is defined elsewhere, usually in a separate source
code module.

printf("%d\n", a); it prints the value of local variable int a = 20. Because, whenever
there is a conflict between local variable and global variable, local variable gets the highest priority. So it prints 20. View Answer Workspace Report Discuss in Forum 4.

What is the output of the program in Turbo C (in DOS 16-bit OS)?

#include<stdio.h>
int main() { char *s1; char far *s2; char huge *s3; printf("%d, %d, %d\n", sizeof(s1), sizeof(s2), sizeof(s3)); return 0; } A. C. 2, 4, 6 2, 4, 4 B. D. 4, 4, 2 2, 2, 2

Answer & Explanation

Answer: Option C Explanation: Any pointer size is 2 bytes. (only 16-bit offset) So, char *s1 = 2 bytes. So, char far *s2; = 4 bytes. So, char huge *s3; = 4 bytes. A far, huge pointer has two parts: a 16-bit segment value and a 16-bit offset value. Since C is a compiler dependent language, it may give different output in other platforms. The above program works fine in Windows (TurboC), but error in Linux (GCC Compiler). View Answer Workspace Report Discuss in Forum 5.

What is the output of the program

#include<stdio.h>
int main() { struct emp { char name[20]; int age; float sal; };

struct emp e = {"Tiger"}; printf("%d, %f\n", e.age, e.sal); return 0; } A. C. 0, 0.000000 Error B. D. Garbage values None of above

Answer & Explanation

Answer: Option A Explanation: When an automatic structure is partially initialized remaining elements are initialized to 0(zero).

6.

What will be the output of the program?

#include<stdio.h>
int X=40; int main() { int X=20; printf("%d\n", X); return 0; } A. C. 20 Error B. D. 40 No Output

Answer & Explanation

Answer: Option A Explanation: Whenever there is conflict between a local variable and global variable, the local variable gets priority. View Answer Workspace Report Discuss in Forum 7.

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. C. 0 Error B. D. 1 None of these

Answer & Explanation

Answer: Option B Explanation: Since x < y turns to be TRUE it is replaced by 1. Then 1 < z is compared and to beTRUE. The 1 is assigned to i. View Answer Workspace Report Discuss in Forum 8.

What is the output of the program

#include<stdio.h>
int main() { extern int fun(float); int a; a = fun(3.14); printf("%d\n", a); return 0; } int fun(int aa) { return (int)++aa; } A. C. E. 3 0 Compile Error B. D. 3.14 4

Answer & Explanation

Answer: Option E Explanation: 2 Errors

1. Type mismatch in redeclaration of fun 2. Type mismatch in parameter aa View Answer Workspace Report Discuss in Forum 9.

What is the output of the program

#include<stdio.h>
int main() { int a[5] = {2, 3}; printf("%d, %d, %d\n", a[2], a[3], a[4]); return 0; } A. C. Garbage Values 3, 2, 2 B. D. 2, 3, 3 0, 0, 0

Answer & Explanation

Answer: Option D Explanation: When an automatic array is partially initialized, the remaining elements are initialized to 0. View Answer Workspace Report Discuss in Forum 10. What is the output of the program?

#include<stdio.h>
int main() { union a { int i; char ch[2]; }; union a u; u.ch[0] = 3; u.ch[1] = 2; printf("%d, %d, %d\n", u.ch[0], u.ch[1], u.i); return 0; } A. C. 3, 2, 515 3, 2, 5 B. D. 515, 2, 3 None of these

Answer & Explanation

Answer: Option A Explanation:

printf("%d, %d, %d\n", u.ch[0], u.ch[1], u.i); It prints the value ofu.ch[0] = 3, u.ch[1] = 2 and it prints the value of u.i means the value of entire union size.

So the output is 3, 2, 515. 11. In the following program how long will the for loop get executed?

#include<stdio.h>
int main() { int i=5; for(;scanf("%s", &i); printf("%d\n", i)); return 0; } A. B. C. D. The for loop would not get executed at all The for loop would get executed only once The for loop would get executed 5 times The for loop would get executed infinite times

Answer & Explanation

Answer: Option D

Explanation: During the for loop execution scanf() ask input and then printf() prints that given input. This process will be continued repeatedly because, scanf() returns the number of input given, the condition is always true(user gives a input means it reurns '1'). Hence this for loop would get executed infinite times. View Answer Workspace Report Discuss in Forum 12. What will be the output of the program?

#include<stdio.h>
int main() { int X=40; { int X=20; printf("%d ", X); } printf("%d\n", X); return 0; } A. C. 40 40 20 B. D. 20 40 Error

Answer & Explanation

Answer: Option B Explanation: In case of a conflict between a local variable and global variable, the local variable gets priority. How many times "IndiaBIX" is get printed?

#include<stdio.h>
int main() { int x; for(x=-1; x<=10; x++) { if(x < 5) continue; else break; printf("IndiaBIX"); } return 0; }

A. C.

Infinite times 0 times

B. D.

11 times 10 times

Answer & Explanation

Answer: Option C Explanation: No answer description available for this question. Let us discuss. View Answer Workspace Report Discuss in Forum 2. 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; } A. C. Infinite times 256 times B. D. 255 times 254 times

Answer & Explanation

Answer: Option B Explanation: The while(j <= 255) loop will get executed 255 times. The size short int(2 byte wide) does not affect the while() loop. View Answer Workspace Report Discuss in Forum 3.

Which of the following is not logical operator? A. C. & || B. D. && !

Answer & Explanation

Answer: Option A Explanation: Bitwise operators: & is a Bitwise AND operator. Logical operators: && is a Logical AND operator. || is a Logical OR operator. ! is a NOT operator. So, '&' is not a Logical operator. View Answer Workspace Report Discuss in Forum 4.

In mathematics and computer programming, which is the correct order of mathematical operators ? A. B. C. D. Addition, Subtraction, Multiplication, Division Division, Multiplication, Addition, Subtraction Multiplication, Addition, Division, Subtraction Addition, Division, Modulus, Subtraction

Answer & Explanation

Answer: Option B Explanation: Simply called as BODMAS (Brackets, Order, Division, Multiplication, Addition and Subtraction). Mnemonics are often used to help students remember the rules, but the rules taught by the use of acronyms can be misleading. In the United States the acronym PEMDAS is common. It stands for Parentheses, Exponents, Multiplication, Division, Addition, Subtraction. In other English speaking countries, Parentheses may be called Brackets, or symbols of inclusion and Exponentiation may be called either Indices, Powers or Orders, and since multiplication and division are of equal precedence, M and D are often interchanged, leading to such acronyms as BEDMAS, BIDMAS, BODMAS, BERDMAS, PERDMAS, and BPODMAS. For more info: http://en.wikipedia.org/wiki/Order_of_operations View Answer Workspace Report Discuss in Forum

5.

Which of the following cannot be checked in a switch-case statement? A. C. Character Float B. D. Integer enum

Answer & Explanation

Answer: Option C Explanation: The switch/case statement in the c language is defined by the language specification to use an int value, so you can not use a float value.

switch( expression ) { case constant-expression1: case constant-expression2: case constant-expression3: ... ... default : statements 4; }

statements 1; statements 2; statements3 ;

The value of the 'expression' in a switch-case statement must be an integer, char, short, long. Float and double are not allowed.

1.

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; } A. C. 0, 1, 2, 3, 4, 5 1, 2, 3, 4 B. D. 5 6

Answer & Explanation

Answer: Option D

Explanation: Step 1: int i = 0; here variable i is an integer type and initialized to '0'. Step 2: for(; i<=5; i++); variable i=0 is already assigned in previous step. The semi-colon at the end of this for loop tells, "there is no more statement is inside the loop". Loop 1: here i=0, the condition in for(; 0<=5; i++) loop satisfies and then i is incremented by '1'(one) Loop 2: here i=1, the condition in for(; 1<=5; i++) loop satisfies and then i is incremented by '1'(one) Loop 3: here i=2, the condition in for(; 2<=5; i++) loop satisfies and then i is incremented by '1'(one) Loop 4: here i=3, the condition in for(; 3<=5; i++) loop satisfies and then i is increemented by '1'(one) Loop 5: here i=4, the condition in for(; 4<=5; i++) loop satisfies and then i is incremented by '1'(one) Loop 6: here i=5, the condition in for(; 5<=5; i++) loop satisfies and then i is incremented by '1'(one) Loop 7: here i=6, the condition in for(; 6<=5; i++) loop fails and then i is not incremented. Step 3: printf("%d", i); here the value of i is 6. Hence the output is '6'. View Answer Workspace Report Discuss in Forum 2.

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; } A. C. C-program Error B. D. Ps None of above

Answer & Explanation

Answer: Option A Explanation: Step 1: char str[]="C-program"; here variable str contains "C-program". Step 2: int a = 5; here variable a contains "5". Step 3: printf(a >10?"Ps\n":"%s\n", str); this statement can be written as

if(a > 10) { printf("Ps\n"); } else { printf("%s\n", str); }


Here we are checking a > 10 means 5 > 10. Hence this condition will be failed. So it prints variable str. Hence the output is "C-program". View Answer Workspace Report Discuss in Forum 3.

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; } A. C. b = 300 c = 200 b = 300 c = garbage B. D. b = 100 c = garbage b = 100 c = 200

Answer & Explanation

Answer: Option D Explanation: Initially variables a = 500, b = 100 and c is not assigned. Step Step Step Step Step Step 1: 2: 3: 4: 5: 6:

if(!a >= 400) if(!500 >= 400) if(0 >= 400) if(FALSE) Hence the if condition is failed. So, variable c is assigned to a value '200'. printf("b = %d c = %d\n", b, c); It prints value of b and c.

Hence the output is "b = 100 c = 200" View Answer Workspace Report Discuss in Forum 4.

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; } A. B. C. D. Infinite loop 0 1 2 ... 65535 0 1 2 ... 32767 - 32766 -32765 -1 0 No output

Answer & Explanation

Answer: Option A Explanation: Here unsigned int size is 2 bytes. It varies from 0,1,2,3, ... to 65535. Step 1:unsigned int i = 65535; Step 2: Loop 1: while(i++ != 0) this statement becomes while(65535 != 0). Hence the while(TRUE) condition is satisfied. Then the printf("%d", ++i); prints '1'(variable 'i' is already increemented by '1' in while statement and now increemented by '1' in printf statement) Loop 2: while(i++ != 0) this statement becomes while(1 != 0). Hence the while(TRUE) condition is satisfied. Then theprintf("%d", ++i); prints '3'(variable 'i' is already increemented by '1' in while statement and now increemented by '1' in printf statement) .... .... The while loop will never stops executing, because variable i will never become '0'(zero). Hence it is an 'Infinite loop'. View Answer Workspace Report Discuss in Forum

5.

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; } A. C. x and y are equal Unpredictable B. D. x and y are not equal No output

Answer & Explanation

Answer: Option A Explanation: Step 1: int x = 3; here variable x is an integer type and initialized to '3'. Step 2: float y = 3.0; here variable y is an float type and initialized to '3.0' Step 3: if(x == y) here we are comparing if(3 == 3.0) hence this condition is satisfied. Hence it prints "x and y are equal".

6.

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; } A. C. 1 ... 65535 No output B. D. Expression syntax error 0, 1, 2, 3, 4, 5

Answer & Explanation

Answer: Option A

Explanation:

for(i<=5 && i>=-1; ++i; i>0) so expression i<=5 && i>=-1 initializes forloop. expression ++i is the loop condition. expression i>0 is the increment expression.
In for( i <= 5 && i >= -1; ++i; i>0) expression i<=5 && i>=-1 evaluates to one. Loop condition always get evaluated to true. Also at this point it increases i by one. An increment_expression i>0 has no effect on value of i.so for loop get executed till the limit of integer (ie. 65535) View Answer Workspace Report Discuss in Forum 7.

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; } A. C. It matters matters B. D. It doesn't matters No output

Answer & Explanation

Answer: Option B Explanation:

printf() returns the number of charecters printed on the console.


Step 1: if(ch = printf("")) here printf() does not print anything, so it returns '0'(zero). Step 2: if(ch = 0) here variable ch has the value '0'(zero). Step 3: if(0) Hence the if condition is not satisfied. So it prints the elsestatements. Hence the output is "It doesn't matters". Note: Compiler shows a warning "possibly incorrect assinment". View Answer Workspace Report Discuss in Forum

8.

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; } A. B. C. D. Infinite loop 0 1 2 ... 65535 0 1 2 ... 32767 - 32766 -32765 -1 0 No output

Answer & Explanation

Answer: Option D Explanation: Here unsigned int size is 2 bytes. It varies from 0,1,2,3, ... to 65535. Step 1:unsigned int i = 65536; here variable i becomes '0'(zero). becauseunsigned int varies from 0 to 65535. Step 2: while(i != 0) this statement becomes while(0 != 0). Hence thewhile(FALSE) condition is not satisfied. So, the inside the statements of whileloop will not get executed. Hence there is no output. Note: Don't forget that the size of int should be 2 bytes. If you run the above program in GCC it may run infinite loop, because in Linux platform the size of the integer is 4 bytes. View Answer Workspace Report Discuss in Forum 9.

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. C. Hi Hi Hello B. D. Hello None of above

Answer & Explanation

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 View Answer Workspace Report Discuss in Forum 10. 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; } A. C. 0, 1, 3 3, 1, 3 B. D. 1, 2, 3 1, 3, 1

Answer & Explanation

Answer: Option C Explanation: Step 1: int a=0, b=1, c=3; here variable a, b, and c are declared as integer type and initialized to 0, 1, 3 respectively. Step 2: *((a) ? &b : &a) = a ? b : c; The right side of the expression(a?b:c) becomes (0?1:3). Hence it return the value '3'. The left side of the expression *((a) ? &b : &a) becomes *((0) ? &b : &a). Hence this contains the address of the variable a *(&a). Step 3: *((a) ? &b : &a) = a ? b : c; Finally this statement becomes *(&a)=3. Hence the variable a has the value '3'. Step 4: printf("%d, %d, %d\n", a, b, c); It prints "3, 1, 3".

You might also like