• No results found

C Programming Test

N/A
N/A
Protected

Academic year: 2021

Share "C Programming Test"

Copied!
116
0
0

Loading.... (view fulltext now)

Full text

(1)

C Programming Test

1 .

A preprocessor directive is a message from programmer to the preprocessor.

A.True B.False

Answer: Option A Explanation:

True, the programmer tells the compiler to include the preprocessor when compiling.

Learn more problems on : C Preprocessor Discuss about this problem : Discuss in Forum

2 .

What will be the output of the program?

#include<stdio.h> int main()

{

int i=2;

printf("%d, %d\n", ++i, ++i); return 0;

}

A.3, 4 B.4, 3 C.4, 4

D.Output may vary from compiler to compiler

Answer: Option D Explanation:

The order of evaluation of arguments passed to a function call is unspecified.

Anyhow, we consider ++i, ++i are Right-to-Left associativity. The output of the program is 4, 3.

In TurboC, the output will be 4, 3. In GCC, the output will be 4, 4.

(2)

Discuss about this problem : Discuss in Forum

3 .

Consider the following program and what will be content of t?

#include<stdio.h> int main() { FILE *fp; int t; fp = fopen("DUMMY.C", "w"); t = fileno(fp); printf("%d\n", t); return 0; }

A.size of "DUMMY.C" file

B.The handle associated with "DUMMY.C" file C.Garbage value

D.Error in fileno()

Answer: Option B Explanation:

fp = fopen("DUMMY.C", "w"); A file DUMMY.C is opened in write mode and returns the file

pointer to fp

t = fileno(fp); returns the handle for the fp stream and it stored in the variable t printf("%d\n", t); It prints the handle number.

Learn more problems on : Input / Output Discuss about this problem : Discuss in Forum

4

. Point out the error in the following program.

#include<stdio.h> void display(int (*ff)()); int main() { int show(); int (*f)(); f = show; display(f); return 0; } void display(int (*ff)()) { (*ff)(); }

(3)

int show() {

printf("IndiaBIX"); }

A.Error: invalid parameter in function

display()

B.Error: invalid function call f=show; C.No error and prints "IndiaBIX" D.No error and prints nothing.

Answer: Option C

Learn more problems on : Complicated Declarations Discuss about this problem : Discuss in Forum

5 .

What will be the output of the program (myprog.c) given below if it is executed from the command line?

cmd> myprog friday tuesday sunday

/* myprog.c */ #include<stdio.h>

int main(int argc, char *argv[]) { printf("%c", *++argv[1]); return 0; } A.r B.f C.m D.y Answer: Option A

Learn more problems on : Command Line Arguments Discuss about this problem : Discuss in Forum

6 .

If the following program (myproc.c) is present in the directory "C:\TC" then what will be output of the program if run it from DOS shell?

/* myproc.c */ #include<stdio.h>

int main(int argc, char *argv[]) { printf("%s", argv[0]); return 0; } A.SAMPLE.C B.C:\TC\MYPROC.EXE C.C:\TC D.Error

(4)

Answer: Option B Explanation:

In order to execute it from DOS shell, we have to run the created EXE file by entering the exe file name as C:\TC>myproc <enter>.

Learn more problems on : Command Line Arguments Discuss about this problem : Discuss in Forum

7 .

Which of the following is correct about err used in the declaration given below?

typedef enum error { warning, test, exception } err;

A.It is a typedef for enum error. B.It is a variable of type enum error. C.The statement is erroneous. D.It is a structure.

Answer: Option A Explanation:

A typedef gives a new name to an existing data type. So err is a new name for enum error.

Learn more problems on : Declarations and Initializations Discuss about this problem : Discuss in Forum

8 .

What will be the output of the program?

#include<stdio.h> int main() { int i=3; switch(i) { case 1: printf("Hello\n"); case 2: printf("Hi\n"); case 3: continue; default: printf("Bye\n"); } return 0; }

(5)

C.No output D.Hello Hi

Answer: Option A Explanation:

The keyword continue cannot be used in switch case. It must be used in for or while or do

while loop. If there is any looping statement in switch case then we can use continue.

Learn more problems on : Control Instructions Discuss about this problem : Discuss in Forum

9 .

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.2, 4, 6 B. 4, 4, 2 C.2, 4, 4 D.2, 2, 2 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 ohter platforms. The above program works fine in Windows (TurboC), but error in Linux (GCC Compiler).

Learn more problems on : Declarations and Initializations Discuss about this problem : Discuss in Forum

10

. In the following program add a statement in the function fun() such that address of a gets stored in j?

(6)

int main() { int *j; void fun(int**); fun(&j); return 0; } void fun(int **k) { int a=10;

/* Add a statement here */ }

A.**k=a; B.k=&a;

C.*k=&a D.&k=*a

Answer: Option C

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

11 .

What will be the output of the program ?

#include<stdio.h> int main() { FILE *ptr; char i; ptr = fopen("myfile.c", "r"); while((i=fgetc(ptr))!=NULL) printf("%c", i); return 0; }

A.Print the contents of file "myfile.c"

B.Print the contents of file "myfile.c" upto NULL character C.Infinite loop

D.Error in program

Answer: Option C Explanation:

The program will generate infinite loop. When an EOF is encountered fgetc() returns EOF. Instead of checking the condition for EOF we have checked it for NULL. so the program will generate infinite loop.

Learn more problems on : Input / Output Discuss about this problem : Discuss in Forum

(7)

12

. Can I increase the size of statically allocated array?A.Yes B.No

Answer: Option B

Learn more problems on : Memory Allocation Discuss about this problem : Discuss in Forum

13

. What will be the output of the program ?

#include<stdio.h> int main() { int arr[1]={10}; printf("%d\n", 0[arr]); return 0; } A.1 B.10 C.0 D.6 Answer: Option B Explanation:

Step 1: int arr[1]={10}; The variable arr[1] is declared as an integer array with size '2' and

it's first element is initialized to value '10'(means arr[0]=10)

Step 2: printf("%d\n", 0[arr]); It prints the first element value of the variable arr.

Hence the output of the program is 10.

Learn more problems on : Arrays

Discuss about this problem : Discuss in Forum

14

. When we mention the prototype of a function?A.Defining B.Declaring

C.Prototyping D.Calling

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.

(8)

While a function definition specifies what a function does, a function prototype can be thought of as specifying its interface.

Learn more problems on : Declarations and Initializations Discuss about this problem : Discuss in Forum

15

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

B.rem = modf(3.14, 2.1); C.rem = fmod(3.14, 2.1);

D.Remainder cannot be obtain in floating point division.

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

Learn more problems on : Declarations and Initializations Discuss about this problem : Discuss in Forum

16 .

What will be the output of the program?

#include<stdio.h>

#define MAX(a, b) (a > b ? a : b) int main()

{

(9)

x = MAX(3+2, 2+7); printf("%d\n", x); return 0; } A.8 B.9 C.6 D.5 Answer: Option B Explanation:

The macro MAX(a, b) (a > b ? a : b) returns the biggest value of the given two numbers.

Step 1 : int x; The variable x is declared as an integer type. Step 2 : x = MAX(3+2, 2+7); becomes,

=> x = (3+2 > 2+7 ? 3+2 : 2+7) => x = (5 > 9 ? 5 : 9)

=> x = 9

Step 3 : printf("%d\n", x); It prints the value of variable x.

Hence the output of the program is 9.

Learn more problems on : C Preprocessor Discuss about this problem : Discuss in Forum

17 .

What will be the output of the program?

#include<stdio.h>

#define JOIN(s1, s2) printf("%s=%s %s=%s \n", #s1, s1, #s2, s2); int main() { char *str1="India"; char *str2="BIX"; JOIN(str1, str2); return 0; }

A.str1=IndiaBIX str2=BIX B.str1=India str2=BIX

C.str1=India str2=IndiaBIX D.Error: in macro substitution

Answer: Option B

(10)

Discuss about this problem : Discuss in Forum

18 .

Point out the error in the following code?

typedef struct { int data; NODEPTR link; }*NODEPTR; A.Error: in *NODEPTR

B.Error: typedef cannot be used until it is defined C.No error

D.None of above

Answer: Option B

Learn more problems on : Typedef

Discuss about this problem : Discuss in Forum

19 .

Point out the error in the program?

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

struct emp e[10]; int i;

for(i=0; i<=9; i++)

scanf("%s %f", e[i].name, &e[i].sal); return 0;

}

A.Error: invalid structure member

B.Error: Floating point formats not linked C.No error

D.None of above

Answer: Option B Explanation:

At run time it will show an error then program will be terminated. Sample output: Turbo C (Windows)

(11)

c:\>myprogram

Sample

12.123

scanf : floating point formats not linked Abnormal program termination

Learn more problems on : Structures, Unions, Enums Discuss about this problem : Discuss in Forum

20 .

What will be the output of the program ?

#include<stdio.h> int main() { char str[] = "peace"; char *s = str; printf("%s\n", s++ +3); return 0; } A.peace B.eace C.ace D.ce Answer: Option D

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

1. 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;

}

1 : The printf() function is called 10 times.

2 : The program will produce the output x = 10 y = 10 3 : The ; after the if(x!=y) will NOT produce an error. 4 : The program will not produce output.

A.1 B.2, 3

(12)

Answer: Option B

Learn more problems on : Control Instructions Discuss about this problem : Discuss in Forum

2 .

What will be the output of the program?

#include<stdio.h> int main() { int k, num=30; k = (num>5 ? (num <=10 ? 100 : 200): 500); printf("%d\n", num); return 0; } A.200 B.30 C.100 D.500 Answer: Option B Explanation:

Step 1: int k, num=30; here variable k and num are declared as an integer type and variable

num is initialized to '30'.

Step 2: k = (num>5 ? (num <=10 ? 100 : 200): 500); This statement does not affect the output

of the program. Because we are going to print the variable num in the next statement. So, we skip this statement.

Step 3: printf("%d\n", num); It prints the value of variable num '30' Step 3: Hence the output of the program is '30'

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum

3 .

Point out the error in the following program.

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

struct emp e[10]; int i;

for(i=0; i<=9; i++)

scanf("%s %f", e[i].name, &e[i].sal); return 0;

(13)

}

A.Suspicious pointer conversion

B.Floating point formats not linked (Run time error)

C.Cannot use scanf() for structures

D.Strings cannot be nested inside structures

Answer: Option B Explanation:

Compile and Run the above program in Turbo C:

C:\>myprogram.exe Sundar

2555.50

scanf : floating point formats not linked Abnormal program termination

The program terminates abnormally at the time of entering the float value for e[i].sal.

Solution:

Just add the following function in your program. It will force the compiler to include required libraries for handling floating point linkages.

static void force_fpf() /* A dummy function */ {

float x, *y; /* Just declares two variables */ y = &x; /* Forces linkage of FP formats */ x = *y; /* Suppress warning message about x */ }

Learn more problems on : Floating Point Issues Discuss about this problem : Discuss in Forum

4 .

The keyword used to transfer control from a function back to the calling function is

A.switch B.goto

C.go back D.return

Answer: Option D Explanation:

(14)

Example:

#include<stdio.h>

int add(int, int); /* Function prototype */ int main() { int a = 4, b = 3, c; c = add(a, b); printf("c = %d\n", c); return 0; }

int add(int a, int b) {

/* returns the value and control back to main() function */ return (a+b);

}

Output:

c = 7

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum

5

. Which of the following statements are correct about the function?

long fun(int num) {

int i; long f=1;

for(i=1; i<=num; i++) f = f * i;

return f; }

A.The function calculates the value of 1 raised to power num. B.The function calculates the square root of an integer

C.The function calculates the factorial value of an integer D.None of above

Answer: Option C Explanation:

Yes, this function calculates and return the factorial value of an given integer num.

Learn more problems on : Functions

(15)

6

. Which of the statements is correct about the program?

#include<stdio.h> int main() { float a=3.14; char *j; j = (char*)&a; printf("%d\n", *j); return 0; }

A.It prints ASCII value of the binary number present in the first byte of a float variable a. B.It prints character equivalent of the binary number present in the first byte of a float variable a. C.It will print 3

D.It will print a garbage value

Answer: Option A

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

7 .

Will the program compile in Turbo C?

#include<stdio.h> int main() { int a=10, *j; void *k; j=k=&a; j++; k++; printf("%u %u\n", j, k); return 0; } A.Yes B.No Answer: Option B Explanation:

Error in statement k++. We cannot perform arithmetic on void pointers.

The following error will be displayed while compiling above program in TurboC. Compiling PROGRAM.C:

(16)

Error PROGRAM.C 8: Size of the type is unknown or zero.

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

8 .

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.

A.1 B.1,4 C.2, 3 D. 2, 4 Answer: Option B Explanation:

1. The array int num[26]; can store 26 elements. This statement is true.

2. The expression num[1] designates the very first element in the array. This statement is false, because it designates the second element of the array.

3. It is necessary to initialize the array at the time of declaration. This statement is false.

4. The declaration num[SIZE] is allowed if SIZE is a macro. This statement is true, because the MACRO just replaces the symbol SIZE with given value.

Hence the statements '1' and '4' are correct statements.

Learn more problems on : Arrays

Discuss about this problem : Discuss in Forum

9 .

The library function used to find the last occurrence of a character in a string is A.strnstr(

) B.laststr()

C.strrchr() D.strstr()

Answer: Option C Explanation:

(17)

Declaration: char *strrchr(const char *s, int c);

It scans a string s in the reverse direction, looking for a specific character c.

Example:

#include <string.h> #include <stdio.h> int main(void) {

char text[] = "I learn through IndiaBIX.com"; char *ptr, c = 'i';

ptr = strrchr(text, c); if (ptr)

printf("The position of '%c' is: %d\n", c, ptr-text); else

printf("The character was not found\n"); return 0;

}

Output:

The position of 'i' is: 19

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum

10 .

If char=1, int=4, and float=4 bytes size, What will be the output of the program ?

#include<stdio.h> int main()

{

char ch = 'A';

printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14f)); return 0; } A.1, 2, 4 B. 1, 4, 4 C.2, 2, 4 D.2, 4, 8 Answer: Option B Explanation:

(18)

value 'A'.

Step 2:

printf("%d, %d, %d", sizeof(ch), sizeof('A'), sizeof(3.14));

The sizeof function returns the size of the given expression.

sizeof(ch) becomes sizeof(char). The size of char is 1 byte.

sizeof('A') becomes sizeof(65). The size of int is 4 bytes (as mentioned in the question). sizeof(3.14f). The size of float is 4 bytes.

Hence the output of the program is 1, 4, 4

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum

11

. What will be the output of the program ?

#include<stdio.h> int main() { char str[] = "Nagpur"; str[0]='K'; printf("%s, ", str); str = "Kanpur"; printf("%s", str+1); return 0; }

A.Kagpur, Kanpur B.Nagpur, Kanpur

C.Kagpur, anpur D.Error

Answer: Option D Explanation:

The statement str = "Kanpur"; generates the LVALUE required error. We have to use strcpy function to copy a string.

To remove error we have to change this statement str = "Kanpur"; to strcpy(str, "Kanpur"); The program prints the string "anpur"

(19)

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum

12 .

What will be the output of the program ?

#include<stdio.h> 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: Option A

Learn more problems on : Structures, Unions, Enums Discuss about this problem : Discuss in Forum

13 .

Bit fields CANNOT be used in union.

A.True B.False

Answer: Option B Explanation:

The following is the example program to explain "using bit fields inside an union".

#include<stdio.h> union Point

{

unsigned int x:4; unsigned int y:4; int res; }; int main() { union Point pt; pt.x = 2; pt.y = 3; pt.res = pt.y;

(20)

return 0; }

// Output: The value of res = 3

Learn more problems on : Structures, Unions, Enums Discuss about this problem : Discuss in Forum

14 .

Which of the following statement is correct about the program?

#include<stdio.h> int main() { FILE *fp; char ch; int i=1; fp = fopen("myfile.c", "r"); while((ch=getc(fp))!=EOF) { if(ch == '\n') i++; } fclose(fp); return 0; }

A.The code counts number of characters in the file B.The code counts number of words in the file C.The code counts number of blank lines in the file D.The code counts number of lines in the file

Answer: Option D Explanation:

This program counts the number of lines in the file myfile.c by counting the character '\n' in that file.

Learn more problems on : Input / Output Discuss about this problem : Discuss in Forum

15

. The first argument to be supplied at command-line must always be count of total arguments.A.True B.False

Answer: Option B

Learn more problems on : Command Line Arguments Discuss about this problem : Discuss in Forum

(21)

16

. What will be the output of the program?

#include<stdio.h> int main()

{

char c=48; int i, mask=01; for(i=1; i<=5; i++) { printf("%c", c|mask); mask = mask<<1; } return 0; } A.1240 0 B. 1248 0 C.12500 D.12556 Answer: Option B

Learn more problems on : Bitwise Operators Discuss about this problem : Discuss in Forum

17 .

What is the output of the program?

typedef struct data; {

int x; sdata *b; }sdata;

A.Error: Declaration missing ';' B.Error: in typedef

C.No error D.None of above

Answer: Option A Explanation:

since the type 'sdata' is not known at the point of declaring the structure

Learn more problems on : Typedef

Discuss about this problem : Discuss in Forum

18

(22)

A.varagrg.h B.stdlib.h

C.stdio.h D.stdarg.h

Answer: Option D

Learn more problems on : Variable Number of Arguments Discuss about this problem : Discuss in Forum

19 .

Point out the error in the following program.

#include<stdio.h> #include<stdarg.h> void varfun(int n, ...); int main() { varfun(3, 7, -11.2, 0.66); return 0; } void varfun(int n, ...) { float *ptr; int num; va_start(ptr, n);

num = va_arg(ptr, int); printf("%d", num); }

A.Error: too many parameters

B.Error: invalid access to list member C.Error: ptr must be type of va_list

D.No error

Answer: Option C

Learn more problems on : Variable Number of Arguments Discuss about this problem : Discuss in Forum

20 .

va_list is an array that holds information needed by va_arg and va_end

A.True B.False

Answer: Option A

Learn more problems on : Variable Number of Arguments Discuss about this problem : Discuss in Forum

(23)

#include<stdio.h> int main() { int j=1; while(j <= 255) { printf("%c %d\n", j, j); j++; } return 0; }

A.Infinite times B.255 times

C.256 times D.254 times

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.

Learn more problems on : Control Instructions Discuss about this problem : Discuss in Forum

2 .

Which of the following errors would be reported by the compiler on compiling the program given below? #include<stdio.h> int main() { int a = 5; switch(a) { case 1: printf("First"); case 2: printf("Second"); case 3 + 2: printf("Third"); case 5: printf("Final"); break; } return 0; }

(24)

B.Expression as in case 3 + 2 is not allowed. C.Duplicate case case 5:

D.No error will be reported.

Answer: Option C Explanation:

Because, case 3 + 2: and case 5: have the same constant value 5.

Learn more problems on : Control Instructions Discuss about this problem : Discuss in Forum

3 .

Point out the error, if any in the program.

#include<stdio.h> int main() { int P = 10; switch(P) { case 10: printf("Case 1"); case 20: printf("Case 2"); break; case P: printf("Case 2"); break; } return 0; }

A.Error: No default value is specified

B.Error: Constant expression required at line case

P:

C.Error: There is no break statement in each case. D.No error will be reported.

Answer: Option B Explanation:

The compiler will report the error "Constant expression required" in the line case P: . Because, variable names cannot be used with case statements.

(25)

The case statements will accept only constant expression.

Learn more problems on : Control Instructions Discuss about this problem : Discuss in Forum

4 .

What will be the output of the program?

#include<stdio.h> int main()

{

int i=2;

printf("%d, %d\n", ++i, ++i); return 0; } A.3, 4 B.4, 3 C.4, 4

D.Output may vary from compiler to compiler

Answer: Option D Explanation:

The order of evaluation of arguments passed to a function call is unspecified.

Anyhow, we consider ++i, ++i are Right-to-Left associativity. The output of the program is 4, 3.

In TurboC, the output will be 4, 3. In GCC, the output will be 4, 4.

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum

5 .

In the expression a=b=5 the order of Assignment is NOT decided by Associativity of operators

A.True B.False

Answer: Option B Explanation:

(26)

The equal to = operator has Right-to-Left Associativity. So it assigns b=5 then a=b.

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum

6 .

What is the notation for following functions?

1. int f(int a, float b) { /* Some code */ } 2. int f(a, b) int a; float b; { /* Some code */ } A. 1. KR Notation 2. ANSI Notation B. 1. Pre ANSI C Notation 2. KR Notation C. 1. ANSI Notation 2. KR Notation D. 1. ANSI Notation 2. Pre ANSI Notation Answer: Option C Explanation:

KR Notation means Kernighan and Ritche Notation.

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum

7

. How many times the program will print "IndiaBIX" ?

#include<stdio.h> int main() { printf("IndiaBIX"); main(); return 0; }

A.Infinite times B.32767 times

C.65535 times D.Till stack doesn't overflow

(27)

Explanation:

A call stack or function stack is used for several related purposes, but the main reason for having one is to keep track of the point to which each active subroutine should return control when it finishes executing.

A stack overflow occurs when too much memory is used on the call stack.

Here function main() is called repeatedly and its return address is stored in the stack. After stack memory is full. It shows stack overflow error.

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum

8 .

What will be the output of the program?

#include<stdio.h> #define SQR(x)(x*x) int main() { int a, b=3; a = SQR(b+2); printf("%d\n", a); return 0; } A.2 5 B. 1 1

C.Error D.Garbage value

Answer: Option B Explanation:

The macro function SQR(x)(x*x) calculate the square of the given number 'x'. (Eg: 102)

Step 1: int a, b=3; Here the variable a, b are declared as an integer type and the variable b is

initialized to 3.

Step 2: a = SQR(b+2); becomes,

=> a = b+2 * b+2; Here SQR(x) is replaced by macro to x*x . => a = 3+2 * 3+2;

(28)

=> a = 11;

Step 3: printf("%d\n", a); It prints the value of variable 'a'.

Hence the output of the program is 11

Learn more problems on : C Preprocessor Discuss about this problem : Discuss in Forum

9 .

A preprocessor directive is a message from programmer to the preprocessor.

A.True B.False

Answer: Option A Explanation:

True, the programmer tells the compiler to include the preprocessor when compiling.

Learn more problems on : C Preprocessor Discuss about this problem : Discuss in Forum

10 .

What will be the output of the program ?

#include<stdio.h> int main() { char *p; p="hello"; printf("%s\n", *&*&p); return 0; } A.llo B.hello C.ello D.h Answer: Option B

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

11

. How will you free the allocated memory ?A.remove(var-name); B.free(var-name); C.delete(var-name); D.dalloc(var-name);

(29)

Learn more problems on : Structures, Unions, Enums Discuss about this problem : Discuss in Forum

12 .

In a file contains the line "I am a boy\r\n" then on reading this line into the array str using

fgets(). What will str contain?

A."I am a boy\r\n\0" B."I am a boy\r\0" C."I am a

boy\n\0" D."I am a boy"

Answer: Option C Explanation:

Declaration: char *fgets(char *s, int n, FILE *stream);

fgets reads characters from stream into the string s. It stops when it reads either n - 1

characters or a newline character, whichever comes first. Therefore, the string str contain "I am a boy\n\0"

Learn more problems on : Input / Output Discuss about this problem : Discuss in Forum

13 .

Which files will get closed through the fclose() in the following program?

#include<stdio.h> int main() { FILE *fs, *ft, *fp; fp = fopen("A.C", "r"); fs = fopen("B.C", "r"); ft = fopen("C.C", "r"); fclose(fp, fs, ft); return 0; } A."A.C" "B.C" "C.C" B."B.C" "C.C" C."A.C" D.Error in fclose()

Answer: Option D Explanation:

(30)

Learn more problems on : Input / Output Discuss about this problem : Discuss in Forum

14 .

If the file 'source.txt' contains a line "Be my friend" which of the following will be the output of below program? #include<stdio.h> int main() { FILE *fs, *ft; char c[10]; fs = fopen("source.txt", "r"); c[0] = getc(fs); fseek(fs, 0, SEEK_END); fseek(fs, -3L, SEEK_CUR); fgets(c, 5, fs); puts(c); return 0; } A.friend B.frien C.end D.Error in fseek(); Answer: Option C Explanation:

The file source.txt contains "Be my friend".

fseek(fs, 0, SEEK_END); moves the file pointer to the end of the file.

fseek(fs, -3L, SEEK_CUR); moves the file pointer backward by 3 characters. fgets(c, 5, fs); read the file from the current position of the file pointer.

Hence, it contains the last 3 characters of "Be my friend". Therefore, it prints "end".

Learn more problems on : Input / Output Discuss about this problem : Discuss in Forum

15 .

According to ANSI specifications which is the correct way of declaring main when it receives command-line arguments?

A.int main(int argc, char *argv[])

(31)

C.

int main() {

int argc; char *argv; }

D.None of above

Answer: Option A

Learn more problems on : Command Line Arguments Discuss about this problem : Discuss in Forum

16 .

What will be the output of the program (myprog.c) given below if it is executed from the command line?

cmd> myprog one two three

/* myprog.c */ #include<stdio.h> #include<stdlib.h>

int main(int argc, char **argv) { printf("%s\n", *++argv); return 0; } A.myprog B.one C.two D.three Answer: Option B

Learn more problems on : Command Line Arguments Discuss about this problem : Discuss in Forum

17 .

Point out the correct statement which correctly allocates memory dynamically for 2D array following program? #include<stdio.h> #include<stdlib.h> int main() { int *p, i, j;

/* Add statement here */ for(i=0; i<3; i++)

{ for(j=0; j<4; j++) { p[i*4+j] = i; printf("%d", p[i*4+j]); } }

(32)

return 0; }

A.p = (int*) malloc(3, 4);

B.p = (int*) malloc(3*sizeof(int)); C.p = malloc(3*4*sizeof(int)); D.p = (int*) malloc(3*4*sizeof(int));

Answer: Option D

Learn more problems on : Memory Allocation Discuss about this problem : Discuss in Forum

18 .

malloc() allocates memory from the heap and not from the stack.

A.True B.False

Answer: Option A

Learn more problems on : Memory Allocation Discuss about this problem : Discuss in Forum

19

. Point out the error in the following program.

#include<stdio.h> #include<stdarg.h> void display(char *s, ...); int fun1(); int fun2(); int main() { int (*p1)(); int (*p2)(); p1 = fun1; p2 = fun2; display("IndiaBIX", p1, p2); return 0; } void display(char *s, ...) { int (*pp1)(); int (*pp2)(); va_list ptr; va_start(ptr, s); pp1 = va_arg(ptr, int(*)()); (*pp1)(); pp2 = va_arg(ptr, int(*)()); (*pp2)(); }

(33)

int fun1() { printf("Hello"); } int fun2() { printf("Hi"); }

A.Error: invalid function display() call

B.Error: invalid va_start(ptr, s);

C.Error: va_arg cannot extract function pointer from variable argument list. D.Error: Rvalue required for

t

Answer: Option C

Learn more problems on : Variable Number of Arguments Discuss about this problem : Discuss in Forum

20

. What do the following declaration signify?

int (*ptr)[30];

A.ptr is a pointer to an array of 30 integer pointers. B.ptr is a array of 30 integer function pointer. C.ptr is a array of 30 integer pointers.

D.ptr is a array 30 pointers.

Answer: Option A

Learn more problems on : Complicated Declarations Discuss about this problem : Discuss in Forum

1. 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; } A.#include<conio.h> B.#include<math.h> C.#include<stdlib.h> D.#include<dos.h> Answer: Option B

(34)

Explanation:

math.h is a header file in the standard library of C programming language designed for basic

mathematical operations.

Declaration syntax: double log(double);

Learn more problems on : Floating Point Issues Discuss about this problem : Discuss in Forum

2 .

What will be the output of the program?

#include<stdio.h>

#define PRINT(i) printf("%d,",i) int main() { int x=2, y=3, z=4; PRINT(x); PRINT(y); PRINT(z); return 0; } A.2, 3, 4 B. 2, 2, 2 C.3, 3, 3 D.4, 4, 4 Answer: Option A Explanation:

The macro PRINT(i) print("%d,", i); prints the given variable value in an integer format.

Step 1: int x=2, y=3, z=4; The variable x, y, z are declared as an integer type and initialized to

2, 3, 4 respectively.

Step 2: PRINT(x); becomes printf("%d,",x). Hence it prints '2'. Step 3: PRINT(y); becomes printf("%d,",y). Hence it prints '3'. Step 4: PRINT(z); becomes printf("%d,",z). Hence it prints '4'.

Hence the output of the program is 2, 3, 4.

(35)

Discuss about this problem : Discuss in Forum

3 .

What will be the output of the program assuming that the array begins at the location 1002 and size of an integer is 4 bytes?

#include<stdio.h> int main()

{

int a[3][4] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; printf("%u, %u, %u\n", a[0]+1, *(a[0]+1), *(*(a+0)+1)); return 0; } A.448, 4, 4 B. 520, 2, 2 C.1006, 2, 2 D.Error Answer: Option C

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

4 .

Which of the following statements correct about k used in the below statement?

char ****k;

A.k is a pointer to a pointer to a pointer to a char

B.k is a pointer to a pointer to a pointer to a pointer to a char C.k is a pointer to a char pointer

D.k is a pointer to a pointer to a char

Answer: Option B

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

5 .

What does the following declaration mean?

int (*ptr)[10];

A.ptr is array of pointers to 10 integers B.ptr is a pointer to an array of 10 integers C.ptr is an array of 10 integers

D.ptr is an pointer to array

Answer: Option B

(36)

Discuss about this problem : Discuss in Forum

6 .

What will be the output of the program in Turbo-C ?

#include<stdio.h> int main()

{

int arr[5], i=-1, z; while(i<5)

arr[i]=++i; for(i=0; i<5; i++)

printf("%d, ", arr[i]); return 0; } A.1, 2, 3, 4, 5, B.-1, 0, 1, 2, 3, 4 C.0, 1, 2, 3, 4, D. 0, -1, -2, -3, -4, Answer: Option C Explanation:

Since C is a compiler dependent language, it may give different outputs at different platforms. We have given the Turbo-C Compiler (under DOS) output.

Please try the above programs in Windows (Turbo-C Compiler) and Linux (GCC Compiler), you will understand the difference better.

Learn more problems on : Arrays

Discuss about this problem : Discuss in Forum

7 .

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

#include<stdio.h> int main()

{

printf("%d, %d, %d", sizeof(3.0f), sizeof('3'), sizeof(3.0)); return 0; } A.8, 1, 4 B. 4, 2, 8 C.4, 2, 4 D.10, 3, 4 Answer: Option B

(37)

Explanation: Step 1:

printf("%d, %d, %d", sizeof(3.0f), sizeof('3'), sizeof(3.0));

The sizeof function returns the size of the given expression.

sizeof(3.0f) is a floating point constant. The size of float is 4 bytes sizeof('3') It converts '3' in to ASCII value.. The size of int is 2 bytes sizeof(3.0) is a double constant. The size of double is 8 bytes

Hence the output of the program is 4,2,8

Note: The above program may produce different output in other platform due to the platform dependency of C compiler.

In Turbo C, 4 2 8. But in GCC, the output will be 4 4 8.

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum

8 .

Point out the error in the program?

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

struct emp e[10]; int i;

for(i=0; i<=9; i++)

scanf("%s %f", e[i].name, &e[i].sal); return 0;

}

A.Error: invalid structure member

B.Error: Floating point formats not linked C.No error

(38)

Answer: Option B Explanation:

At run time it will show an error then program will be terminated. Sample output: Turbo C (Windows)

c:\>myprogram

Sample

12.123

scanf : floating point formats not linked Abnormal program termination

Learn more problems on : Structures, Unions, Enums Discuss about this problem : Discuss in Forum

9 .

A structure can contain similar or dissimilar elements

A.True B.False

Answer: Option A

Learn more problems on : Structures, Unions, Enums Discuss about this problem : Discuss in Forum

10 .

A pointer union CANNOT be created

A.Yes B.No

Answer: Option B

Learn more problems on : Structures, Unions, Enums Discuss about this problem : Discuss in Forum

11 .

What will be the output of the program if value 25 given to scanf()?

#include<stdio.h> int main()

{

int i;

printf("%d\n", scanf("%d", &i)); return 0;

}

(39)

C.1 D.5

Answer: Option C Explanation:

The scanf function returns the number of input is given.

printf("%d\n", scanf("%d", &i)); The scanf function returns the value 1(one).

Therefore, the output of the program is '1'.

Learn more problems on : Input / Output Discuss about this problem : Discuss in Forum

12

. Point out the error in the program?

#include<stdio.h> #include<stdlib.h> int main() { unsigned char; FILE *fp; fp=fopen("trial", "r"); if(!fp) {

printf("Unable to open file"); exit(1);

}

fclose(fp); return 0; }

A.Error: in unsigned char statement B.Error: unknown file pointer

C.No error D.None of above

Answer: Option C Explanation:

This program tries to open the file trial.txt in read mode. If file not exists or unable to read it prints "Unable to open file" and then terminate the program.

(40)

Learn more problems on : Input / Output Discuss about this problem : Discuss in Forum

13 .

What will be the output of the program (sample.c) given below if it is executed from the command line (turbo c under DOS)?

cmd> sample Good Morning

/* sample.c */ #include<stdio.h>

int main(int argc, char *argv[]) {

printf("%d %s", argc, argv[1]); return 0;

}

A.3 Good B.2 Good

C.Good Morning D.3 Morning

Answer: Option A

Learn more problems on : Command Line Arguments Discuss about this problem : Discuss in Forum

14 .

What will be the output of the program (sample.c) given below if it is executed from the command line?

cmd> sample friday tuesday sunday

/* sample.c */ #include<stdio.h>

int main(int argc, char *argv[]) { printf("%c", *++argv[2] ); return 0; } A.s B.f C.u D.r Answer: Option C

Learn more problems on : Command Line Arguments Discuss about this problem : Discuss in Forum

15

(41)

Answer: Option A

Learn more problems on : Command Line Arguments Discuss about this problem : Discuss in Forum

16 .

If the different command line arguments are supplied at different times would the output of the following program change?

#include<stdio.h>

int main(int argc, char **argv) { printf("%d\n", argv[argc]); return 0; } A.Yes B.No Answer: Option B

Learn more problems on : Command Line Arguments Discuss about this problem : Discuss in Forum

17

. What will be the output of the program?

#include<stdio.h>

typedef struct error {int warning, err, exception;} ERROR; int main() { ERROR e; e.err=1; printf("%d\n", e.err); return 0; } A.0 B.1 C.2 D.Error Answer: Option B

Learn more problems on : Typedef

Discuss about this problem : Discuss in Forum

18

. What will be the output of the program?

#include<stdio.h> int main()

{

(42)

printf("%d\n", i++); return 0; } A.1 0 B. 1 1

C.No output D.Error: ++needs a value

Answer: Option D Explanation:

This program will show an error "Cannot modify a const object".

Step 1: const int i=0; The constant variable 'i' is declared as an integer and initialized with

value of '0'(zero).

Step 2: printf("%d\n", i++); Here the variable 'i' is increemented by 1(one). This will create

an error "Cannot modify a const object". Because, we cannot modify a const variable.

Learn more problems on : Const

Discuss about this problem : Discuss in Forum

19 .

Which standard library function will you use to find the last occurance of a character in a string in C?

A.strnchar() B.strchar()

C.strrchar() D.strrchr()

Answer: Option D Explanation:

strrchr() returns a pointer to the last occurrence of character in a string.

Example: #include <stdio.h> #include <string.h> int main() { char str[30] = "12345678910111213";

printf("The last position of '2' is %d.\n", strrchr(str, '2') - str);

(43)

return 0; }

Output: The last position of '2' is 14.

Learn more problems on : Library Functions Discuss about this problem : Discuss in Forum

20 .

Data written into a file using fwrite() can be read back using fscanf()

A.True B.False

Answer: Option B Explanation:

fwrite() - Unformatted write in to a file. fscanf() - Formatted read from a file.

Learn more problems on : Library Functions Discuss about this problem : Discuss in Forum

1. 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.Infinite times B.11 times

C.0 times D.10 times

Answer: Option C

Learn more problems on : Control Instructions Discuss about this problem : Discuss in Forum

2 .

What will be the output of the program?

#include<stdio.h> int main()

(44)

{ int i=-3, j=2, k=0, m; m = ++i && ++j || ++k; printf("%d, %d, %d, %d\n", i, j, k, m); return 0; } A.1, 2, 0, 1 B. -3, 2, 0, 1 C.-2, 3, 0, 1 D.2, 3, 1, 1 Answer: Option C Explanation:

Step 1: int i=-3, j=2, k=0, m; here variable i, j, k, m are declared as an integer type and

variable i, j, k are initialized to -3, 2, 0 respectively.

Step 2: m = ++i && ++j || ++k;

becomes m = (-2 && 3) || ++k; becomes m = TRUE || ++k;.

(++k) is not executed because (-2 && 3) alone return TRUE.

Hence this statement becomes TRUE. So it returns '1'(one). Hence m=1.

Step 3: printf("%d, %d, %d, %d\n", i, j, k, m); In the previous step the value of i,j are

increemented by '1'(one).

Hence the output is "-2, 3, 0, 1".

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum

3

. What will be the output of the program?

#include<stdio.h>

int addmult(int ii, int jj) { int kk, ll; kk = ii + jj; ll = ii * jj; return (kk, ll); } int main() { int i=3, j=4, k, l; k = addmult(i, j); l = addmult(i, j); printf("%d, %d\n", k, l); return 0;

(45)

} A.12, 12 B. 7, 7 C.7, 12 D.12, 7 Answer: Option A Explanation:

Step 1: int i=3, j=4, k, l; The variables i, j, k, l are declared as an integer type and variable i, j

are initialized to 3, 4 respectively.

The function addmult(i, j); accept 2 integer parameters.

Step 2: k = addmult(i, j); becomes k = addmult(3, 4)

In the function addmult(). The variable kk, ll are declared as an integer type int kk, ll;

kk = ii + jj; becomes kk = 3 + 4 Now the kk value is '7'. ll = ii * jj; becomes ll = 3 * 4 Now the ll value is '12'. return (kk, ll); It returns the value of variable ll only.

The value 12 is stored in variable 'k'.

Step 3: l = addmult(i, j); becomes l = addmult(3, 4)

kk = ii + jj; becomes kk = 3 + 4 Now the kk value is '7'. ll = ii * jj; becomes ll = 3 * 4 Now the ll value is '12'. return (kk, ll); It returns the value of variable ll only.

The value 12 is stored in variable 'l'.

Step 4: printf("%d, %d\n", k, l); It prints the value of k and l

Hence the output is "12, 12".

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum

4 .

Will the following program print the message infinite number of times?

(46)

#define INFINITELOOP while(1) int main() { INFINITELOOP printf("IndiaBIX"); return 0; } A.Yes B.No Answer: Option A Explanation:

Yes, the program prints "IndiaBIX" and runs infinitely.

The macro INFINITELOOP while(1) replaces the text 'INFINITELOOP' by 'while(1)' In the main function, while(1) satisfies the while condition and it prints "IndiaBIX". Then it comes to while(1) and the loop runs infinitely.

Learn more problems on : C Preprocessor Discuss about this problem : Discuss in Forum

5

. What will be the output of the program ?

#include<stdio.h>

int *check(static int, static int); int main() { int *c; c = check(10, 20); printf("%d\n", c); return 0; }

int *check(static int i, static int j) { int *p, *q; p = &i; q = &j; if(i >= 45) return (p); else return (q); } A.10 B.20

(47)

D.Error: cannot use static for function parameters

Answer: Option D

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

6 .

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;

}

A.10, 2, 4 B.20, 4, 4

C.16, 2, 2 D.20, 2, 2

Answer: Option B

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

7 .

In the following program add a statement in the function fact() such that the factorial gets stored in j. #include<stdio.h> void fact(int*); int main() { int i=5; fact(&i); printf("%d\n", i); return 0; } void fact(int *j) { static int s=1; if(*j!=0) { s = s**j; *j = *j-1; fact(j);

/* Add a statement here */ }

(48)

A.j=s; B.*j=s;

C.*j=&s; D.&j=s;

Answer: Option B

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

8 .

What will be the output of the program if the array begins at address 65486?

#include<stdio.h> int main()

{

int arr[] = {12, 14, 15, 23, 45}; printf("%u, %u\n", arr, &arr); return 0; } A.65486, 65488 B.65486, 65486 C.65486, 65490 D.65486, 65487 Answer: Option B Explanation:

Step 1: int arr[] = {12, 14, 15, 23, 45}; The variable arr is declared as an integer array and

initialized.

Step 2: printf("%u, %u\n", arr, &arr); Here,

The base address of the array is 65486.

=> arr, &arr is pointing to the base address of the array arr. Hence the output of the program is 65486, 65486

Learn more problems on : Arrays

Discuss about this problem : Discuss in Forum

9

. What will be the output of the program ?

#include<stdio.h> int main()

{

int i;

(49)

if(printf("%s", a))

printf("The string is empty\n"); else

printf("The string is not empty\n"); return 0;

}

A.The string is empty B.The string is not empty

C.No output D.0

Answer: Option B Explanation:

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

Step 1: char a[] = "\0"; The variable a is declared as an array of characters and it initialized

with "\0". It denotes that the string is empty.

Step 2: if(printf("%s", a)) The printf() statement does not print anything, so it returns '0'(zero).

Hence the if condition is failed.

In the else part it prints "The string is not empty".

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum

10 .

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

#include<stdio.h> int main()

{

printf("%u %s\n", &"Hello", &"Hello"); return 0;

}

A.177 Hello B.Hello 177

C.Hello Hello D.Error

Answer: Option A Explanation:

In printf("%u %s\n", &"Hello", &"Hello");.

(50)

The %s format specifier tells the compiler to print the string "Hello".

Hence the output of the program is "177 Hello". (Note: 177 is memory address it may change.)

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum

11 .

If a char is 1 byte wide, an integer is 2 bytes wide and a long integer is 4 bytes wide then will the following structure always occupy 7 bytes?

struct ex { char ch; int i; long int a; }; A.Yes B.No Answer: Option B Explanation:

A compiler may leave holes in structures by padding the first char in the structure with another byte just to ensures that the integer that follows is stored at an location. Also, there might be 2extra bytes after the integer to ensure that the long integer is stored at an address, which is multiple of 4. Such alignment is done by machines to improve the efficiency of accessing values.

Learn more problems on : Structures, Unions, Enums Discuss about this problem : Discuss in Forum

12 .

Point out the error/warning in the program?

#include<stdio.h> int main() { unsigned char ch; FILE *fp; fp=fopen("trial", "r"); while((ch = getc(fp))!=EOF) printf("%c", ch); fclose(fp); return 0; }

A.Error: in unsigned char declaration B.Error: while statement

(51)

C.No error

D.It prints all characters in file "trial"

Answer: Option A Explanation:

Here, EOF is -1. As 'ch' is declared as unsigned char it cannot deal with any negative value.

Learn more problems on : Input / Output Discuss about this problem : Discuss in Forum

13 .

What will be the output of the program

#include<stdio.h> void fun(int); int main(int argc) { printf("%d\n", argc); fun(argc); return 0; } void fun(int i) { if(i!=4) main(++i); } A.1 2 3 B.1 2 3 4 C.2 3 4 D.1 Answer: Option B

Learn more problems on : Command Line Arguments Discuss about this problem : Discuss in Forum

14 .

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); }

(52)

return 0; }

A.It prints all even bits from

num

B.It prints all odd bits from num C.It prints binary equivalent num D.Error

Answer: Option C Explanation:

If we give input 4, it will print 00000000 00000100 ; If we give input 3, it will print 00000000 00000011 ; If we give input 511, it will print 00000001 11111111 ;

Learn more problems on : Bitwise Operators Discuss about this problem : Discuss in Forum

15

. What will be the output of the program?

#include<stdio.h> int fun(int **ptr); int main()

{

int i=10;

const int *ptr = &i; fun(&ptr); return 0; } int fun(int **ptr) { int j = 223; int *temp = &j;

printf("Before changing ptr = %5x\n", *ptr); const *ptr = temp; printf("After changing ptr = %5x\n", *ptr); return 0; } A.Address of iAddress of j B. 10 22 3

(53)

D.Garbage value

Answer: Option C

Learn more problems on : Const

Discuss about this problem : Discuss in Forum

16 .

Can I increase the size of dynamically allocated array?

A.Yes B.No

Answer: Option A Explanation:

Use realloc(variable_name, value);

Learn more problems on : Memory Allocation Discuss about this problem : Discuss in Forum

17 .

It is necessary to call the macro va_end if va_start is called in the function.

A.Yes B.No

Answer: Option A

Learn more problems on : Variable Number of Arguments Discuss about this problem : Discuss in Forum

18 .

What do the following declaration signify?

void (*cmp)();

A.cmp is a pointer to an void function type. B.cmp is a void type pointer function.

C.cmp is a function that return a void pointer. D.cmp is a pointer to a function which returns void .

Answer: Option D

Learn more problems on : Complicated Declarations Discuss about this problem : Discuss in Forum

19 .

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

#include<stdio.h> int main()

(54)

{

char huge *near *far *ptr1; char near *far *huge *ptr2; char far *huge *near *ptr3;

printf("%d, %d, %d\n", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3)); return 0; } A.4, 4, 8 B. 2, 4, 4 C.4, 4, 2 D.2, 4, 8 Answer: Option C

Learn more problems on : Complicated Declarations Discuss about this problem : Discuss in Forum

20 .

What will be the output of the program?

#include<stdio.h> #include<stdlib.h> int main() { char *i = "55.555"; int result1 = 10; float result2 = 11.111; result1 = result1+atoi(i); result2 = result2+atof(i);

printf("%d, %f", result1, result2); return 0; } A.55, 55.555 B. 66, 66.666600 C.65, 66.666000 D.55, 55 Answer: Option C Explanation:

Function atoi() converts the string to integer. Function atof() converts the string to float.

result1 = result1+atoi(i);

Here result1 = 10 + atoi(55.555); result1 = 10 + 55;

result1 = 65;

(55)

Here result2 = 11.111 + atof(55.555); result2 = 11.111 + 55.555000;

result2 = 66.666000;

So the output is "65, 66.666000" .

Learn more problems on : Library Functions Discuss about this problem : Discuss in Forum

1. The modulus operator cannot be used with a long double.

A.True B.False

Answer: Option A 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 or long

double divisions.

Learn more problems on : Control Instructions Discuss about this problem : Discuss in Forum

2

. What will be the output of the program?

#include<stdio.h> int main()

{

int i=-3, j=2, k=0, m; m = ++i && ++j && ++k;

printf("%d, %d, %d, %d\n", i, j, k, m); return 0; } A.-2, 3, 1, 1 B.2, 3, 1, 2 C.1, 2, 3, 1 D. 3, 3, 1, 2 Answer: Option A Explanation:

Step 1: int i=-3, j=2, k=0, m; here variable i, j, k, m are declared as an integer type and

variable i, j, k are initialized to -3, 2, 0 respectively.

Step 2: m = ++i && ++j && ++k;

becomes m = -2 && 3 && 1;

(56)

Hence m=1.

Step 3: printf("%d, %d, %d, %d\n", i, j, k, m); In the previous step the value of i,j,k are

increemented by '1'(one).

Hence the output is "-2, 3, 1, 1".

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum

3 .

In a function two return statements should never occur.

A.Yes B.No

Answer: Option B Explanation:

No, In a function two return statements can occur but not successively.

Example:

#include <stdio.h>

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 = 0

(57)

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum

4 .

It is necessary that a header files should have a .h extension?

A.Yes B.No

Answer: Option B Explanation:

No, the header files have any kind of extension.

Learn more problems on : C Preprocessor Discuss about this problem : Discuss in Forum

5 .

How many bytes are occupied by near, far and huge pointers (DOS)? A.near=2 far=4

huge=4 B.

near=4 far=8 huge=8 C.near=2 far=4 huge=8 D.near=4 far=4 huge=8

Answer: Option A Explanation:

near=2, far=4 and huge=4 pointers exist only under DOS. Under windows and Linux every

pointers is 4 bytes long.

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

6 .

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; }

A.x=31, y=502, z=502 B.x=31, y=500, z=500 C.x=31, y=498, z=498 D.x=31, y=504, z=504

(58)

Answer: Option D

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

7 .

What will be the output of the program ?

#include<stdio.h> int main() { void *vp; char ch=74, *cp="JACK"; int j=65; vp=&ch; printf("%c", *(char*)vp); vp=&j; printf("%c", *(int*)vp); vp=cp; printf("%s", (char*)vp+2); return 0; } A.JCK B.J65K C.JAK D.JACK Answer: Option D

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

8 .

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; }

A.Output: Garbage value B.Output: 1

C.Output: 3 D.Error: Invalid indirection

Answer: Option D

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum

(59)

. #include<stdio.h> #include<string.h> int main() { char str[] = "India\0\BIX\0"; printf("%s\n", str); return 0; } A.BIX B.India

C.India BIX D.India\0BIX

Answer: Option B Explanation:

A string is a collection of characters terminated by '\0'.

Step 1: char str[] = "India\0\BIX\0"; The variable str is declared as an array of characters and

initialized with value "India"

Step 2: printf("%s\n", str); It prints the value of the str.

The output of the program is "India".

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum

10 .

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

#include<stdio.h> int main() { struct emp { char *n; int age; };

struct emp e1 = {"Dravid", 23}; struct emp e2 = e1;

strupr(e2.n);

printf("%s\n", e1.n); return 0;

}

A.Error: Invalid structure assignment B.DRAVID

(60)

D.No output

Answer: Option B

Learn more problems on : Structures, Unions, Enums Discuss about this problem : Discuss in Forum

11 .

Point out the error in the program?

#include<stdio.h> int main() { struct a { float category:5; char scheme:4; };

printf("size=%d", sizeof(struct a)); return 0;

}

A.Error: invalid structure member in

printf

B.Error in this float category:5; statement C.No error

D.None of above

Answer: Option B Explanation:

Bit field type must be signed int or unsigned int.

The char type: char scheme:4; is also a valid statement.

Learn more problems on : Structures, Unions, Enums Discuss about this problem : Discuss in Forum

12

. Point out the error in the program?

#include<stdio.h> #include<string.h>

void modify(struct emp*); struct emp { char name[20]; int age; }; int main() {

References

Related documents

Some people define a dream sign as anything that could make you question reality, such as waking up to see that you have no hair, but the majority of lucid dreamers define it

The variations in statistical parameters: Standard deviation, Entropy, Contrast and Energy which quantify weld bead texture by its uniformity and roughness are

z The convergence ring can transmit Native Ethernet services to BSC/RNC directly or through the regional backhaul network through the FE/GE interface.. In

Design: In seven longitudinal studies, we used factor analysis to reduce 21 measures of HDL particle size and lipid content to a smaller number of factors representing

New NSAID medications became available in prescription form that also offered excellent pain relief, but like aspirin, these new prescription medications also had the potential

3.1 The essential features of the MCVN impact test are: (a) a suitable miniature three point bend specimen, (b) anvils and supports on which the test specimen is placed to receive

In The Periodic Payment Settlement Act of 1982 (P.L. 97-473), Congress adopted specific tax rules to encourage the use of structured settlements to resolve physical injury

(c) Every written, recorded, or electronic communication from a lawyer soliciting professional employment from a prospective client potentially in need of legal services in