Top Banner
C Programming Test 1 . A preprocessor directive is a message from programmer to the preprocessor. A . Tru e B . Fal se 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
147
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: C Programming Test

C Programming Test1.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.

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum 3.Consider the following program and what will be content of t?

Page 2: C Programming Test

#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)();}int show(){ printf("IndiaBIX");

Page 3: C Programming Test

}

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

Answer: Option B

Page 4: C Programming Test

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

A.Error: Misplaced continue B.Bye

C.No output D.Hello Hi

Page 5: C Programming Test

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?

#include<stdio.h>int main(){ int *j; void fun(int**);

Page 6: C Programming Test

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 12.Can I increase the size of statically allocated array?

A.Yes B.No

Page 7: C Programming Test

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.

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

Page 8: C Programming Test

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(){ int x; x = MAX(3+2, 2+7); printf("%d\n", x); return 0;}

Page 9: C Programming Test

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

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum 18.Point out the error in the following code?

Page 10: C Programming Test

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)

c:\>myprogram Sample

Page 11: C Programming Test

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 = 103 : The ; after the if(x!=y) will NOT produce an error.4 : The program will not produce output.

A.1 B.2, 3

C.3, 4 D.4

Answer: Option B

Learn more problems on : Control Instructions

Page 12: C Programming Test

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

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

Page 13: C Programming Test

Answer: Option B

Explanation:

Compile and Run the above program in Turbo C:

C:\>myprogram.exeSundar2555.50scanf : floating point formats not linkedAbnormal 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:

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

Example:

#include<stdio.h>int add(int, int); /* Function prototype */

int main(){ int a = 4, b = 3, c;

Page 14: C Programming Test

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

Discuss about this problem : Discuss in Forum 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);

Page 15: C Programming Test

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: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.

Page 16: C Programming Test

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:

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

Page 17: C Programming Test

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:

Step 1: char ch = 'A'; The variable ch is declared as an character type and initialized with 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

Page 18: C Programming Test

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"

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

Page 19: C Programming Test

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;

printf("\n The value of res = %d" , pt.res);

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

Page 20: C Programming Test

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 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.12400 B.12480

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?

Page 21: C Programming Test

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.Which header file should you include, if you are going to develop a function, which can

accept variable number of arguments?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);

Page 22: C Programming Test

}

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

Page 23: C Programming Test

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

A.There is no break statement in each case.

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;

Page 24: C Programming Test

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.

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.

Page 25: C Programming Test

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

operatorsA.True B.False

Answer: Option B

Explanation:

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 NotationD.

1. ANSI Notation 2. Pre ANSI Notation

Answer: Option C

Explanation:

KR Notation means Kernighan and Ritche Notation.

Learn more problems on : Functions

Page 26: C Programming Test

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

Answer: Option D

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.25 B.11

C.Error D.Garbage value

Answer: Option B

Explanation:

Page 27: C Programming Test

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;

=> a = 3 + 6 + 2;

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

Page 28: C Programming Test

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

Answer: Option B

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;

Page 29: C Programming Test

}

A."A.C" "B.C" "C.C" B."B.C" "C.C"

C."A.C" D.Error in fclose()

Answer: Option D

Explanation:

Extra parameter in call to fclose().

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".

Page 30: C Programming Test

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[])

B.int main(argc, argv)int argc; char *argv;

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>

Page 31: C Programming Test

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]); } } 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, ...){

Page 32: C Programming Test

int (*pp1)(); int (*pp2)(); va_list ptr;

va_start(ptr, s); pp1 = va_arg(ptr, int(*)()); (*pp1)();

pp2 = va_arg(ptr, int(*)()); (*pp2)();

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

Page 33: C Programming Test

{ 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

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'.

Page 34: C Programming Test

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

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

Learn more problems on : C Preprocessor

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

Page 35: C Programming Test

D. ptr is an pointer to array

Answer: Option B

Learn more problems on : Arrays

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

Page 36: C Programming Test

Answer: Option B

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

D.None of above

Page 37: C Programming Test

Answer: Option B

Explanation:

At run time it will show an error then program will be terminated.

Sample output: Turbo C (Windows)

c:\>myprogram Sample12.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;}

A.25 B.2

C.1 D.5

Page 38: C Programming Test

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.

If file exists, it simply close the file and then terminates the program.

Page 39: C Programming Test

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.Even if integer/float arguments are supplied at command prompt they are treated as strings.

A.True B.False

Page 40: C Programming Test

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(){ const int i=0;

Page 41: C Programming Test

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

A.10 B.11

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

Page 42: C Programming Test

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(){ int i=-3, j=2, k=0, m;

Page 43: C Programming Test

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

A.12, 12 B.7, 7

Page 44: C Programming Test

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?

#include<stdio.h>#define INFINITELOOP while(1)

int main(){

Page 45: C Programming Test

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

C.Error: Non portable pointer conversion

D.Error: cannot use static for function parameters

Answer: Option D

Page 46: C Programming Test

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 */ }}

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

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

Answer: Option B

Page 47: C Programming Test

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; char a[] = "\0"; if(printf("%s", a)) printf("The string is empty\n"); else printf("The string is not empty\n"); return 0;}

Page 48: C Programming Test

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");.

The %u format specifier tells the compiler to print the memory address of the "Hello".

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.)

Page 49: C Programming Test

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

C.No error

D.It prints all characters in file "trial"

Answer: Option A

Page 50: C Programming Test

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

A.It prints all even bits from num

B.It prints all odd bits from num

Page 51: C Programming Test

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.10223

C.Error: cannot convert parameter 1 from 'const int **' to 'int **'

D.Garbage value

Answer: Option C

Learn more problems on : Const

Discuss about this problem : Discuss in Forum

Page 52: C Programming Test

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(){ 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

Page 53: C Programming Test

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;

result2 = result2+atof(i); 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

Page 54: C Programming Test

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;becomes m = TRUE && 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,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

Page 55: C Programming Test

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

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.

Page 56: C Programming Test

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

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;

Page 57: C Programming Test

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 9.What will be the output of the program ?

#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

Page 58: C Programming Test

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

C.Dravid

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

Page 59: C Programming Test

{ 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(){ struct emp e = {"Sanjay", 35}; modify(&e); printf("%s %d", e.name, e.age); return 0;}void modify(struct emp *p){ p ->age=p->age+2;}

A.Error: in structure

B.Error: in prototype declaration unknown struct emp

C.No error

D.None of above

Page 60: C Programming Test

Answer: Option B

Explanation:

The struct emp is mentioned in the prototype of the function modify() before declaring the structure.To solve this problem declare struct emp before the modify() prototype.

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum 13.The '.' operator can be used access structure elements using a structure variable.

A.True B.False

Answer: Option A

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum 14.Can we specify a variable filed width in a scanf() format string?

A.Yes B.No

Answer: Option B

Explanation:

In scanf() a * in a format string after a % sign is used for the suppression of assignment. That is, the current input field is scanned but not stored.

Learn more problems on : Input / Output

Discuss about this problem : Discuss in Forum 15.Which header file should be included to use functions like malloc() and calloc()?

A.memory.h B.stdlib.h

C.string.h D.dos.h

Answer: Option B

Learn more problems on : Memory Allocation

Discuss about this problem : Discuss in Forum 16.If malloc() successfully allocates memory it returns the number of bytes it has allocated.

A.True B.False

Page 61: C Programming Test

Answer: Option B

Explanation:

Syntax: void *malloc(size_t size);

The malloc() function shall allocate unused space for an object whose size in bytes is specified by size and whose value is unspecified.

The order and contiguity of storage allocated by successive calls to malloc() is unspecified. The pointer returned if the allocation succeeds shall be suitably aligned so that it may be assigned to a pointer to any type of object and then used to access such an object in the space allocated (until the space is explicitly freed or reallocated). Each such allocation shall yield a pointer to an object disjoint from any other object. The pointer returned points to the start (lowest byte address) of the allocated space. If the space cannot be allocated, a null pointer shall be returned. If the size of the space requested is 0, the behavior is implementation-defined: the value returned shall be either a null pointer or a unique pointer.

Learn more problems on : Memory Allocation

Discuss about this problem : Discuss in Forum 17.In a function that receives variable number of arguments the fixed arguments passed to the

function can be at the end of argument list.A.True B.False

Answer: Option B

Learn more problems on : Variable Number of Arguments

Discuss about this problem : Discuss in Forum 18.We can allocate a 2-Dimensional array dynamically.

A.True B.False

Answer: Option A

Learn more problems on : Complicated Declarations

Discuss about this problem : Discuss in Forum 19.Are the following declarations same?

char far *far *scr;char far far** scr;

A.Yes B.No

Page 62: C Programming Test

Answer: Option B

Learn more problems on : Complicated Declarations

Discuss about this problem : Discuss in Forum 20.What is the purpose of fflush() function.

A.flushes all streams and specified streams.

B.flushes only specified stream.

C.flushes input/output buffer.

D.flushes file buffer.

Answer: Option A

Explanation:

"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 Functions

Discuss about this problem : Discuss in Forum 1. 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.1 ... 65535 B.Expression syntax error

C.No output D.0, 1, 2, 3, 4, 5

Answer: Option A

Explanation:

for(i<=5 && i>=-1; ++i; i>0) so expression i<=5 && i>=-1 initializes for loop. expression ++i is the loop condition. expression i>0 is the increment expression.

Page 63: C Programming Test

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)

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(){ float a = 0.7; if(0.7 > a) printf("Hi\n"); else printf("Hello\n"); return 0;}

A.Hi B.Hello

C.Hi Hello D.None of above

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

Learn more problems on : Control Instructions

Discuss about this problem : Discuss in Forum 3.Which of the following statements are correct about an if-else statements in a C-program?

Page 64: C Programming Test

1: Every if-else statement can be replaced by an equivalent statements using   ? ; operators2: Nested if-else statements are allowed.3: Multiple statements in an if block are allowed.4: Multiple statements in an else block are allowed.

A.1 and 2 B.2 and 3

C.1, 2 and 4 D.2, 3, 4

Answer: Option D

Learn more problems on : Control Instructions

Discuss about this problem : Discuss in Forum 4.Can we use a switch statement to switch on strings?

A.Yes B.No

Answer: Option B

Explanation:

The cases in a switch must either have integer constants or constant expressions.

Learn more problems on : Control Instructions

Discuss about this problem : Discuss in Forum 5.What will be the output of the program?

#include<stdio.h>#include<math.h>int main(){ printf("%f\n", sqrt(36.0)); return 0;}

A.6.0 B.6

C.6.000000 D.Error: Prototype sqrt() not found.

Answer: Option C

Explanation:

printf("%f\n", sqrt(36.0)); It prints the square root of 36 in the float format(i.e 6.000000).

Declaration Syntax: double sqrt(double x) calculates and return the positive square root of the

Page 65: C Programming Test

given number.

Learn more problems on : Floating Point Issues

Discuss about this problem : Discuss in Forum 6.Is it true that too many recursive calls may result into stack overflow?

A.Yes B.No

Answer: Option A

Explanation:

Yes, too many recursive calls may result into stack overflow. because when a function is called its return address is stored in stack.

After sometime the stack memory will be filled completely. Hence stack overflow error will occur.

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum 7.A macro must always be defined in capital letters.

A.True B.False

Answer: Option B

Explanation:

FALSE, The macro is case insensitive.

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum 8.In a macro call the control is passed to the macro.

A.True B.False

Answer: Option B

Explanation:

False, Always the macro is substituted by the given text/expression.

Learn more problems on : C Preprocessor

Page 66: C Programming Test

Discuss about this problem : Discuss in Forum 9.A header file contains macros, structure declaration and function prototypes.

A.True B.False

Answer: Option A

Explanation:

True, the header file contains classes, function prototypes, structure declaration, macros.

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum 10.Which of the following function sets first n characters of a string to a given character?

A.strinit() B.strnset()

C.strset() D.strcset()

Answer: Option B

Explanation:

Declaration:

char *strnset(char *s, int ch, size_t n); Sets the first n characters of s to ch

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

int main(void){ char *string = "abcdefghijklmnopqrstuvwxyz"; char letter = 'x';

printf("string before strnset: %s\n", string); strnset(string, letter, 13); printf("string after strnset: %s\n", string);

return 0;}

Output:

string before strnset: abcdefghijklmnopqrstuvwxyz

string after strnset: xxxxxxxxxxxxxnopqrstuvwxyz

Learn more problems on : Strings

Page 67: C Programming Test

Discuss about this problem : Discuss in Forum 11.What will be the output of the program ?

#include<stdio.h>

int main(){ char str1[] = "Hello"; char str2[10]; char *t, *s; s = str1; t = str2; while(*t=*s) *t++ = *s++; printf("%s\n", str2); return 0;}

A.Hello B.HelloHello

C.No output D.ello

Answer: Option A

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(){ char str = "IndiaBIX"; printf("%s\n", str); return 0;}

A.Error B.IndiaBIX

C.Base address of str D.No output

Answer: Option A

Explanation:

The line char str = "IndiaBIX"; generates "Non portable pointer conversion" error.

To eliminate the error, we have to change the above line to

char *str = "IndiaBIX"; (or) char str[] = "IndiaBIX";

Then it prints "IndiaBIX".

Page 68: C Programming Test

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum 13.If the size of pointer is 4 bytes then What will be the output of the program ?

#include<stdio.h>

int main(){ char *str[] = {"Frogs", "Do", "Not", "Die", "They", "Croak!"}; printf("%d, %d", sizeof(str), strlen(str[0])); return 0;}

A.22, 4 B.25, 5

C.24, 5 D.20, 2

Answer: Option C

Explanation:

Step 1: char *str[] = {"Frogs", "Do", "Not", "Die", "They", "Croak!"}; The variable str is declared as an pointer to the array of 6 strings.

Step 2: printf("%d, %d", sizeof(str), strlen(str[0]));

sizeof(str) denotes 6 * 4 bytes = 24 bytes. Hence it prints '24'

strlen(str[0])); becomes strlen(Frogs)). Hence it prints '5';

Hence the output of the program is 24, 5

Hint: If you run the above code in 16 bit platform (Turbo C under DOS) the output will be 12, 5. Because the pointer occupies only 2 bytes. If you run the above code in Linux (32 bit platform), the output will be 24, 5 (because the size of pointer is 4 bytes).

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum 14.Point out the error in the program?

#include<stdio.h>

int main(){ FILE *fp; fp=fopen("trial", "r"); fseek(fp, "20", SEEK_SET); fclose(fp);

Page 69: C Programming Test

return 0;}

A.Error: unrecognised Keyword SEEK_SET

B.Error: fseek() long offset value

C.No error

D.None of above

Answer: Option B

Explanation:

Instead of "20" use 20L since fseek() need a long offset value.

Learn more problems on : Input / Output

Discuss about this problem : Discuss in Forum 15.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 16.What will be the output of the program?

#include<stdio.h>

int main(){ const int x=5; const int *ptrx; ptrx = &x; *ptrx = 10; printf("%d\n", x); return 0;}

Page 70: C Programming Test

A.5 B.10

C.Error D.Garbage value

Answer: Option C

Explanation:

Step 1: const int x=5; The constant variable x is declared as an integer data type and initialized with value '5'.

Step 2: const int *ptrx; The constant variable ptrx is declared as an integer pointer.

Step 3: ptrx = &x; The address of the constant variable x is assigned to integer pointer variable ptrx.

Step 4: *ptrx = 10; Here we are indirectly trying to change the value of the constant vaiable x. This will result in an error.

To change the value of const variable x we have to use *(int *)&x = 10;

Learn more problems on : Const

Discuss about this problem : Discuss in Forum 17.Point out the error in the program (in Turbo-C).

#include<stdio.h>#define MAX 128

int main(){ const int max=128; char array[max]; char string[MAX]; array[0] = string[0] = 'A'; printf("%c %c\n", array[0], string[0]); return 0;}

A.Error: unknown max in declaration/Constant expression required

B.Error: invalid array string

C.None of above

D.No error. It prints A A

Answer: Option A

Explanation:

Page 71: C Programming Test

Step 1: A macro named MAX is defined with value 128

Step 2: const int max=128; The constant variable max is declared as an integer data type and it is initialized with value 128.

Step 3: char array[max]; This statement reports an error "constant expression required". Because, we cannot use variable to define the size of array.

To avoid this error, we have to declare the size of an array as static. Eg. char array[10]; or use macro char array[MAX];

Note: The above program will print A A as output in Unix platform.

Learn more problems on : Const

Discuss about this problem : Discuss in Forum 18.Point out the error in the program.

#include<stdio.h>const char *fun();

int main(){ char *ptr = fun(); return 0;}const char *fun(){ return "Hello";}

A.Error: Lvalue required

B.Error: cannot convert 'const char *' to 'char *'.

C.No error and No output

D.None of above

Answer: Option C

Learn more problems on : Const

Discuss about this problem : Discuss in Forum 19.Input/output function prototypes and macros are defined in which header file?

A.conio.h B.stdlib.h

C.stdio.h D.dos.h

Page 72: C Programming Test

Answer: Option C

Explanation:

stdio.h, which stands for "standard input/output header", is the header in the C standard library that contains macro definitions, constants, and declarations of functions and types used for various standard input and output operations.

Learn more problems on : Library Functions

Discuss about this problem : Discuss in Forum 20.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;}

A.aaaa B.aaaaa

C.Garbage value. D.Error in ungetc statement.

Answer: Option B

Explanation:

for(i=1; i<=5; i++) Here the for loop runs 5 times.

Loop 1: scanf("%c", &c); Here we give 'a' as input. printf("%c", c); prints the character 'a' which is given in the previous "scanf()" statement. ungetc(c, stdin); "ungetc()" function pushes character 'a' back into input stream.

Loop 2: Here the scanf("%c", &c); get the input from "stdin" because of "ungetc" function. printf("%c", c); Now variable c = 'a'. So it prints the character 'a'. ungetc(c, stdin); "ungetc()" function pushes character 'a' back into input stream.

Page 73: C Programming Test

This above process will be repeated in Loop 3, Loop 4, Loop 5.

Learn more problems on : Library Functions

Discuss about this problem : Discuss in Forum 1. A short integer is at least 16 bits wide and a long integer is at least 32 bits wide.

A.True B.False

Answer: Option A

Explanation:

The basic C compiler is 16 bit compiler, below are the size of it's data types The size of short int is 2 bytes wide(16 bits).The size of long int is 4 bytes wide(32 bits).

Learn more problems on : Control Instructions

Discuss about this problem : Discuss in Forum 2.Which of the following correctly shows the hierarchy of arithmetic operations in C?

A./ + * - B.* - / +

C.+ - / * D./ * + -

Answer: Option D

Explanation:

Simply called as BODMAS (Bracket of Division, Multiplication, Addition and Subtraction).

How Do I Remember ? BODMAS !

B - Brackets first O - Orders (ie Powers and Square Roots, etc.) DM - Division and Multiplication (left-to-right) AS - Addition and Subtraction (left-to-right)

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum 3.In which order do the following gets evaluated

1. Relational2. Arithmetic3. Logical

Page 74: C Programming Test

4. Assignment

A.2134 B.1234

C.4321 D.3214

Answer: Option A

Explanation:

2. Arithmetic operators: *, /, %, +, - 1. Relational operators: >, <, >=, <=, ==, !=3. Logical operators : !, &&, ||4. Assignment operators: =

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum 4.Associativity has no role to play unless the precedence of operator is same.

A.True B.False

Answer: Option A

Explanation:

Associativity is only needed when the operators in an expression have the same precedence. Usually + and - have the same precedence.

Consider the expression 7 - 4 + 2. The result could be either (7 - 4) + 2 = 5 or 7 - (4 + 2) = 1. The former result corresponds to the case when + and - are left-associative, the latter to when + and - are right-associative.

Usually the addition, subtraction, multiplication, and division operators are left-associative, while the exponentiation, assignment and conditional operators are right-associative. To prevent cases where operands would be associated with two operators, or no operator at all, operators with the same precedence must have the same associativity.

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum 5.If the binary eauivalent of 5.375 in normalised form is 0100 0000 1010 1100 0000 0000 0000

0000, what will be the output of the program (on intel machine)?

#include<stdio.h>#include<math.h>int main(){ float a=5.375; char *p;

Page 75: C Programming Test

int i; p = (char*)&a; for(i=0; i<=3; i++) printf("%02x\n", (unsigned char)p[i]); return 0;}

A.40 AC 00 00 B.04 CA 00 00

C.00 00 AC 40 D.00 00 CA 04

Answer: Option C

Learn more problems on : Floating Point Issues

Discuss about this problem : Discuss in Forum 6.A float occupies 4 bytes. If the hexadecimal equivalent of these 4 bytes are A, B, C and D, then

when this float is stored in memory in which of the following order do these bytes gets stored?A.ABCD

B.DCBA

C.0xABCD

D.Depends on big endian or little endian architecture

Answer: Option D

Learn more problems on : Floating Point Issues

Discuss about this problem : Discuss in Forum 7.What will be the output of the program?

#include<stdio.h>int sumdig(int);int main(){ int a, b; a = sumdig(123); b = sumdig(123); printf("%d, %d\n", a, b); return 0;}int sumdig(int n){ int s, d; if(n!=0) { d = n%10; n = n/10; s = d+sumdig(n); } else return 0; return s;

Page 76: C Programming Test

}

A.4, 4 B.3, 3

C.6, 6 D.12, 12

Answer: Option C

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum 8.Point out the error in the program

f(int a, int b){ int a; a = 20; return a;}

A.Missing parenthesis in return statement

B.The function should be defined as int f(int a, int b)

C.Redeclaration of a

D.None of above

Answer: Option C

Explanation:

f(int a, int b) The variable a is declared in the function argument statement.

int a; Here again we are declaring the variable a. Hence it shows the error "Redeclaration of a"

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum 9.What will be the output of the program?

#include<stdio.h>#define SQUARE(x) x*x

int main(){ float s=10, u=30, t=2, a; a = 2*(s-u*t)/SQUARE(t); printf("Result = %f", a); return 0;}

A.Result = -100.000000 B.Result = -25.000000

C.Result = 0.000000 D.Result = 100.000000

Page 77: C Programming Test

Answer: Option A

Explanation:

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

Step 1: float s=10, u=30, t=2, a; Here the variable s, u, t, a are declared as an floating point type and the variable s, u, t are initialized to 10, 30, 2.

Step 2: a = 2*(s-u*t)/SQUARE(t); becomes,

=> a = 2 * (10 - 30 * 2) / t * t; Here SQUARE(t) is replaced by macro to t*t .

=> a = 2 * (10 - 30 * 2) / 2 * 2;

=> a = 2 * (10 - 60) / 2 * 2;

=> a = 2 * (-50) / 2 * 2 ;

=> a = 2 * (-25) * 2 ;

=> a = (-50) * 2 ;

=> a = -100;

Step 3: printf("Result=%f", a); It prints the value of variable 'a'.

Hence the output of the program is -100

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum 10.Preprocessor directive #undef can be used only on a macro that has been #define earlier

A.True B.False

Answer: Option A

Explanation:

True, #undef can be used only on a macro that has been #define earlier

Example: #define PI 3.14

We can undefine PI macro by #undef PI

Page 78: C Programming Test

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum 11.Which statement will you add to the following program to ensure that the program outputs

"IndiaBIX" on execution?

#include<stdio.h>

int main(){ char s[] = "IndiaBIX"; char t[25]; char *ps, *pt; ps = s; pt = t; while(*ps) *pt++ = *ps++;

/* Add a statement here */ printf("%s\n", t); return 0;}

A.*pt=''; B.pt='\0';

C.pt='\n'; D.*pt='\0';

Answer: Option D

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum 12.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;}

A.Hello B.World

C.Hello World D.WorldHello

Answer: Option C

Explanation:

Step 1: char str1[20] = "Hello", str2[20] = " World"; The variable str1 and str2 is declared

Page 79: C Programming Test

as an array of characters and initialized with value "Hello" and " World" respectively.

Step 2: printf("%s\n", strcpy(str2, strcat(str1, str2)));

=> strcat(str1, str2)) it append the string str2 to str1. The result will be stored in str1. Therefore str1 contains "Hello World".

=> strcpy(str2, "Hello World") it copies the "Hello World" to the variable str2.

Hence it prints "Hello World".

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum 13.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;}

A.A B.a

C.c D.65

Answer: Option A

Explanation:

Step 1: char p[] = "%d\n"; The variable p is declared as an array of characters and initialized with string "%d".

Step 2: p[1] = 'c'; Here, we overwrite the second element of array p by 'c'. So array p becomes "%c".

Step 3: printf(p, 65); becomes printf("%c", 65);

Therefore it prints the ASCII value of 65. The output is 'A'.

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum 14.What will be the output of the program ?

Page 80: C Programming Test

#include<stdio.h>void swap(char *, char *);

int main(){ char *pstr[2] = {"Hello", "IndiaBIX"}; swap(pstr[0], pstr[1]); printf("%s\n%s", pstr[0], pstr[1]); return 0;}void swap(char *t1, char *t2){ char *t; t=t1; t1=t2; t2=t;}

A.IndiaBIXHello

B.Address of "Hello" and "IndiaBIX"

C.HelloIndiaBIX

D.IelloHndiaBIX

Answer: Option C

Explanation:

Step 1: void swap(char *, char *); This prototype tells the compiler that the function swap accept two strings as arguments and it does not return anything.

Step 2: char *pstr[2] = {"Hello", "IndiaBIX"}; The variable pstr is declared as an pointer to the array of strings. It is initialized to

pstr[0] = "Hello", pstr[1] = "IndiaBIX"

Step 3: swap(pstr[0], pstr[1]); The swap function is called by "call by value". Hence it does not affect the output of the program.

If the swap function is "called by reference" it will affect the variable pstr.

Step 4: printf("%s\n%s", pstr[0], pstr[1]); It prints the value of pstr[0] and pstr[1].

Hence the output of the program is

HelloIndiaBIX

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum

Page 81: C Programming Test

15.What will be the output of the program ?

#include<stdio.h>

int main(){ union var { int a, b; }; union var v; v.a=10; v.b=20; printf("%d\n", v.a); return 0;}

A.10 B.20

C.30 D.0

Answer: Option B

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum 16.Nested unions are allowed

A.True B.False

Answer: Option A

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum 17.Can we have an array of bit fields?

A.Yes B.No

Answer: Option B

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum 18.To scan a and b given below, which of the following scanf() statement will you use?

#include<stdio.h>

float a;double b;

A.scanf("%f %f", &a, &b); B.scanf("%Lf %Lf", &a, &b);

C.scanf("%f %Lf", &a, D.scanf("%f %lf", &a, &b);

Page 82: C Programming Test

&b);

Answer: Option D

Explanation:

To scan a float value, %f is used as format specifier.

To scan a double value, %lf is used as format specifier.

Therefore, the answer is scanf("%f %lf", &a, &b);

Learn more problems on : Input / Output

Discuss about this problem : Discuss in Forum 19.What will be the output of the program?

#define P printf("%d\n", -1^~0);#define M(P) int main()\ {\ P\ return 0;\ }M(P)

A.1 B.0

C.-1 D.2

Answer: Option B

Learn more problems on : Bitwise Operators

Discuss about this problem : Discuss in Forum 20.What will be the output of the program?

#include<stdio.h>

int main(){ unsigned int res; res = (64 >>(2+1-2)) & (~(1<<2)); printf("%d\n", res); return 0;}

A.32 B.64

C.0 D.128

Answer: Option A

Page 83: C Programming Test

Learn more problems on : Bitwise Operators

Discuss about this problem : Discuss in Forum 1. Which of the following cannot be checked in a switch-case statement?

A.Character B.Integer

C.Float D.enum

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: statements 1; case constant-expression2: statements 2; case constant-expression3: statements3 ; ... ... default : statements 4;}

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

Learn more problems on : Control Instructions

Discuss about this problem : Discuss in Forum 2.Point out the error, if any in the program.

#include<stdio.h> int main(){ int a = 10, b; a >=5 ? b=100: b=200; printf("%d\n", b); return 0;}

A.100 B.200

C.Error: L value required for b

D.Garbage value

Answer: Option C

Page 84: C Programming Test

Explanation:

Variable b is not assigned.

It should be like:

b = a >= 5 ? 100 : 200;

Learn more problems on : Control Instructions

Discuss about this problem : Discuss in Forum 3.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;}

A.Error: Statement missing B.Error: Expression syntax

C.Error: Lvalue required

D.Error: Rvalue required

Answer: Option A

Explanation:

This program will result in error "Statement missing ;"

printf("x is less than y\n") here ; is added to the end of this statement.

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=4, j=-1, k=0, w, x, y, z; w = i || j || k;

Page 85: C Programming Test

x = i && j && k; y = i || j &&k; z = i && j || k; printf("%d, %d, %d, %d\n", w, x, y, z); return 0;}

A.1, 1, 1, 1 B.1, 1, 0, 1

C.1, 0, 0, 1 D.1, 0, 1, 1

Answer: Option D

Explanation:

Step 1: int i=4, j=-1, k=0, w, x, y, z; here variable i, j, k, w, x, y, z are declared as an integer type and the variable i, j, k are initialized to 4, -1, 0 respectively.

Step 2: w = i || j || k; becomes w = 4 || -1 || 0;. Hence it returns TRUE. So, w=1

Step 3: x = i && j && k; becomes x = 4 && -1 && 0; Hence it returns FALSE. So, x=0

Step 4: y = i || j &&k; becomes y = 4 || -1 && 0; Hence it returns TRUE. So, y=1

Step 5: z = i && j || k; becomes z = 4 && -1 || 0; Hence it returns TRUE. So, z=1.

Step 6: printf("%d, %d, %d, %d\n", w, x, y, z); Hence the output is "1, 0, 1, 1".

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum 5.Are the following two statement same?

1. a <= 20 ? b = 30: c = 30;2. (a <=20) ? b : c = 30;

A.Yes B.No

Answer: Option B

Explanation:

No, the expressions 1 and 2 are not same.

1. a <= 20 ? b = 30: c = 30; This statement can be rewritten as,

if(a <= 20){ b = 30;

Page 86: C Programming Test

}else{ c = 30;}

2. (a <=20) ? b : c = 30; This statement can be rewritten as,

if(a <= 20){ //Nothing here}else{ c = 30;}

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum 6.Macros have a local scope.

A.True B.False

Answer: Option B

Explanation:

False, The scope of macros is globals and functions. Also the scope of macros is only from the point of definition to the end of the file.

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum 7.What will be the output of the program ?

#include<stdio.h>

int main(){ char *str; str = "%d\n"; str++; str++; printf(str-2, 300); return 0;}

A.No output B.30

C.3 D.300

Page 87: C Programming Test

Answer: Option D

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum 8.Is this a correct way for NULL pointer assignment?

int i=0;char *q=(char*)i;

A.Yes B.No

Answer: Option B

Explanation:

The correct way is char *q=0 (or) char *q=(char*)0

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum 9.What will be the output of the program if the array begins at 65472 and each integer occupies 2

bytes?

#include<stdio.h>

int main(){ int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0}; printf("%u, %u\n", a+1, &a+1); return 0;}

A.65474, 65476 B.65480, 65496

C.65480, 65488 D.65474, 65488

Answer: Option B

Explanation:

Step 1: int a[3][4] = {1, 2, 3, 4, 4, 3, 2, 1, 7, 8, 9, 0}; The array a[3][4] is declared as an integer array having the 3 rows and 4 colums dimensions.

Step 2: printf("%u, %u\n", a+1, &a+1);

The base address(also the address of the first element) of array is 65472.

For a two-dimensional array like a reference to array has type "pointer to array of 4 ints". Therefore, a+1 is pointing to the memory location of first element of the second row in array a.

Page 88: C Programming Test

Hence 65472 + (4 ints * 2 bytes) = 65480

Then, &a has type "pointer to array of 3 arrays of 4 ints", totally 12 ints. Therefore, &a+1 denotes "12 ints * 2 bytes * 1 = 24 bytes".

Hence, begining address 65472 + 24 = 65496. So, &a+1 = 65496

Hence the output of the program is 65480, 65496

Learn more problems on : Arrays

Discuss about this problem : Discuss in Forum 10.The library function used to reverse a string is

A.strstr() B.strrev()

C.revstr() D.strreverse()

Answer: Option B

Explanation:

strrev(s) Reverses all characters in s

Example:

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

int main(void){ char *str = "IndiaBIX";

printf("Before strrev(): %s\n", str); strrev(str); printf("After strrev(): %s\n", str); return 0;}

Output:

Before strrev(): IndiaBIX

After strrev(): XIBaidnI

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum 11.What will be the output of the program ?

Page 89: C Programming Test

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

int main(){ char sentence[80]; int i; printf("Enter a line of text\n"); gets(sentence); for(i=strlen(sentence)-1; i >=0; i--) putchar(sentence[i]); return 0;}

A.The sentence will get printed in same order as it entered

B.The sentence will get printed in reverse order

C.Half of the sentence will get printed

D.None of above

Answer: Option B

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum 12.What will be the output of the program ?

#include<stdio.h>

struct course { int courseno; char coursename[25]; };int main(){ struct course c[] = { {102, "Java"}, {103, "PHP"}, {104, "DotNet"} };

printf("%d", c[1].courseno); printf("%s\n", (*(c+2)).coursename); return 0;}

A.103 Dotnet B.102 Java

C.103 PHP D.104 DotNet

Answer: Option A

Page 90: C Programming Test

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum 13.Point out the error in the program?

struct emp{ int ecode; struct emp *e;};

A.Error: in structure declaration

B.Linker Error

C.No Error

D.None of above

Answer: Option C

Explanation:

This type of declaration is called as self-referential structure. Here *e is pointer to a struct emp.

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum 14.On declaring a structure 0 bytes are reserved in memory.

A.True B.False

Answer: Option B

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum 15.On executing the below program what will be the contents of 'target.txt' file if the source file

contains a line "To err is human"?

#include<stdio.h>

int main(){ int i, fss; char ch, source[20] = "source.txt", target[20]="target.txt", t; FILE *fs, *ft; fs = fopen(source, "r"); ft = fopen(target, "w"); while(1) {

Page 91: C Programming Test

ch=getc(fs); if(ch==EOF) break; else { fseek(fs, 4L, SEEK_CUR); fputc(ch, ft); } } return 0;}

A.r n B.Trh

C.err D.None of above

Answer: Option B

Explanation:

The file source.txt is opened in read mode and target.txt is opened in write mode. The file source.txt contains "To err is human".

Inside the while loop,

ch=getc(fs); The first character('T') of the source.txt is stored in variable ch and it's checked for EOF.

if(ch==EOF) If EOF(End of file) is true, the loop breaks and program execution stops.

If not EOF encountered, fseek(fs, 4L, SEEK_CUR); the file pointer advances 4 character from the current position. Hence the file pointer is in 5th character of file source.txt.

fputc(ch, ft); It writes the character 'T' stored in variable ch to target.txt.

The while loop runs three times and it write the character 1st and 5th and 11th characters ("Trh") in the target.txt file.

Learn more problems on : Input / Output

Discuss about this problem : Discuss in Forum 16.What will be the output of the program (sample.c) given below if it is executed from the

command line (Turbo C in DOS)?cmd> sample 1 2 3

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

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

Page 92: C Programming Test

j = argv[1] + argv[2] + argv[3]; printf("%d", j); return 0;}

A.6 B.sample 6

C.Error D.Garbage value

Answer: Option C

Explanation:

Here argv[1], argv[2] and argv[3] are string type. We have to convert the string to integer type before perform arithmetic operation.

Example: j = atoi(argv[1]) + atoi(argv[2]) + atoi(argv[3]);

Learn more problems on : Command Line Arguments

Discuss about this problem : Discuss in Forum 17.In Turbo C/C++ under DOS if we want that any wild card characters in the command-line

arguments should be appropriately expanded, are we required to make any special provision?A.Yes B.No

Answer: Option A

Explanation:

Yes you have to compile a program liketcc myprog wildargs.obj

Learn more problems on : Command Line Arguments

Discuss about this problem : Discuss in Forum 18.Bitwise | can be used to multiply a number by powers of 2.

A.Yes B.No

Answer: Option B

Learn more problems on : Bitwise Operators

Discuss about this problem : Discuss in Forum 19.What do the following declaration signify?

int *f();

A. f is a pointer variable of function type.

Page 93: C Programming Test

B. f is a function returning pointer to an int.

C. f is a function pointer.

D. f is a simple declaration of pointer variable.

Answer: Option B

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>

int main(){ 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, 4 B.4, 2, 2

C.2, 8, 4 D.2, 4, 8

Answer: Option B

Learn more problems on : Complicated Declarations

Discuss about this problem : Discuss in Forum 1. 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;}

A.

2 13 14 15 16 17 0

B.

2 13 14 15 16 1

Page 94: C Programming Test

C.

2 13 14 15 1

D.

2 23 34 45 5

Answer: Option A

Learn more problems on : Control Instructions

Discuss about this problem : Discuss in Forum 2.Which of the following is the correct order of evaluation for the below expression?

z = x + y * z / 4 % 2 - 1A.* / % + - = B.= * / % + -

C./ * % - + = D.* % / - + =

Answer: Option A

Explanation:

C uses left associativity for evaluating expressions to break a tie between two operators having same precedence.

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum 3.Which of the following range is a valid long double ?

A.3.4E-4932 to 1.1E+4932 B.3.4E-4932 to 3.4E+4932

C.1.1E-4932 to 1.1E+4932 D.1.7E-4932 to 1.7E+4932

Answer: Option A

Explanation:

The range of long double is 3.4E-4932 to 1.1E+4932

Learn more problems on : Floating Point Issues

Discuss about this problem : Discuss in Forum 4.Will the printf() statement print the same values for any values of a?

#include<stdio.h>int main(){ float a; scanf("%f", &a); printf("%f\n", a+a+a); printf("%f\n", 3*a);

Page 95: C Programming Test

return 0;}

A.Yes B.No

Answer: Option A

Learn more problems on : Floating Point Issues

Discuss about this problem : Discuss in Forum 5.What will be the output of the program?

#include<stdio.h>#include<stdlib.h>

int main(){ int i=0; i++; if(i<=5) { printf("IndiaBIX"); exit(1); main(); } return 0;}

A.Prints "IndiaBIX" 5 times

B.Function main() doesn't calls itself

C.Infinite loop

D.Prints "IndiaBIx"

Answer: Option D

Explanation:

Step 1: int i=0; The variable i is declared as in integer type and initialized to '0'(zero).

Step 2: i++; Here variable i is increemented by 1. Hence i becomes '1'(one).

Step 3: if(i<=5) becomes if(1 <=5). Hence the if condition is satisfied and it enter into if block statements.

Step 4: printf("IndiaBIX"); It prints "IndiaBIX".

Step 5: exit(1); This exit statement terminates the program execution.

Hence the output is "IndiaBIx".

Page 96: C Programming Test

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum 6.What will be the output of the program ?

#include<stdio.h>

int main(){ int i, a[] = {2, 4, 6, 8, 10}; change(a, 5); for(i=0; i<=4; i++) printf("%d, ", a[i]); return 0;}change(int *b, int n){ int i; for(i=0; i<n; i++) *(b+1) = *(b+i)+5;}

A.7, 9, 11, 13, 15 B.2, 15, 6, 8, 10

C.2 4 6 8 10 D.3, 1, -1, -3, -5

Answer: Option B

Learn more problems on : Pointers

Discuss about this problem : Discuss in Forum 7.What will be the output of the program if the array begins 1200 in memory?

#include<stdio.h>

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

A.1200, 1202, 1204 B.1200, 1200, 1200

C.1200, 1204, 1208 D.1200, 1202, 1200

Answer: Option B

Explanation:

Step 1: int arr[]={2, 3, 4, 1, 6}; The variable arr is declared as an integer array and initialized.

Page 97: C Programming Test

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

The base address of the array is 1200.

=> arr, &arr is pointing to the base address of the array arr.

=> &arr[0] is pointing to the address of the first element array arr. (ie. base address)

Hence the output of the program is 1200, 1200, 1200

Learn more problems on : Arrays

Discuss about this problem : Discuss in Forum 8.Which of the following is correct way to define the function fun() in the below program?

#include<stdio.h>

int main(){ int a[3][4]; fun(a); return 0;}

A.void fun(int p[][4]){}

B.void fun(int *p[4]){}

C.void fun(int *p[][4]){}

D.void fun(int *p[3][4]){}

Answer: Option A

Explanation:

void fun(int p[][4]){ } is the correct way to write the function fun(). while the others are considered only the function fun() is called by using call by reference.

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(){ printf(5+"IndiaBIX\n"); return 0;}

Page 98: C Programming Test

A.Error B.IndiaBIX

C.BIX D.None of above

Answer: Option C

Explanation:

printf(5+"IndiaBIX\n"); In the printf statement, it skips the first 5 characters and it prints "BIX"

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum 10.What will be the output of the program ?

#include<stdio.h>

int main(){ enum status {pass, fail, absent}; enum status stud1, stud2, stud3; stud1 = pass; stud2 = absent; stud3 = fail; printf("%d %d %d\n", stud1, stud2, stud3); return 0;}

A.0, 1, 2 B.1, 2, 3

C.0, 2, 1 D.1, 3, 2

Answer: Option C

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum 11.Point out the error in the program?

struct emp{ int ecode; struct emp e;};

A.Error: in structure declaration

B.Linker Error

C.No Error

D.None of above

Page 99: C Programming Test

Answer: Option A

Explanation:

The structure emp contains a member e of the same type.(i.e) struct emp. At this stage compiler does not know the size of sttructure.

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum 12.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 13.While calling the fprintf() function in the format string conversion specifier %s can be used to

write a character string in capital letters.A.True B.False

Answer: Option B

Page 100: C Programming Test

Explanation:

The %s format specifier tells the compiler the given input was string of characters.

Learn more problems on : Input / Output

Discuss about this problem : Discuss in Forum 14.The maximum combined length of the command-line arguments including the spaces between

adjacent arguments isA.128 characters

B.256 characters

C.67 characters

D.It may vary from one operating system to another

Answer: Option D

Learn more problems on : Command Line Arguments

Discuss about this problem : Discuss in Forum 15.Which of the following statements are correct about the program?

#include<stdio.h>char *fun(unsigned int num, int base);

int main(){ char *s; s=fun(128, 2); s=fun(128, 16); printf("%s\n",s); return 0;}char *fun(unsigned int num, int base){ static char buff[33]; char *ptr = &buff[sizeof(buff)-1]; *ptr = '\0'; do { *--ptr = "0123456789abcdef"[num %base]; num /=base; }while(num!=0); return ptr;}

A.It converts a number to a given base.

B.It converts a number to its equivalent binary.

C.It converts a number to its equivalent hexadecimal.

Page 101: C Programming Test

D.It converts a number to its equivalent octal.

Answer: Option A

Learn more problems on : Bitwise Operators

Discuss about this problem : Discuss in Forum 16.What will be the output of the program?

#include<stdio.h>

int main(){ const c = -11; const int d = 34; printf("%d, %d\n", c, d); return 0;}

A.Error B.-11, 34

C.11, 34 D.None of these

Answer: Option B

Explanation:

Step 1: const c = -11; The constant variable 'c' is declared and initialized to value "-11".

Step 2: const int d = 34; The constant variable 'd' is declared as an integer and initialized to value '34'.

Step 3: printf("%d, %d\n", c, d); The value of the variable 'c' and 'd' are printed.

Hence the output of the program is -11, 34

Learn more problems on : Const

Discuss about this problem : Discuss in Forum 17.Point out the correct statement will let you access the elements of the array using 'p' in the

following program?

#include<stdio.h>#include<stdlib.h>

int main(){ int i, j; int(*p)[3]; p = (int(*)[3])malloc(3*sizeof(*p)); return 0;

Page 102: C Programming Test

}

A.

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

B.for(i=0; i<3; i++) printf("%d", p[i]);

C.

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

D.for(j=0; j<3; j++) printf("%d", p[i][j]);

Answer: Option C

Learn more problems on : Memory Allocation

Discuss about this problem : Discuss in Forum 18.What do the following declaration signify?

char *arr[10];

A. arr is a array of 10 character pointers.

B. arr is a array of function pointer.

C. arr is a array of characters.

D. arr is a pointer to array of characters.

Answer: Option A

Learn more problems on : Complicated Declarations

Discuss about this problem : Discuss in Forum 19.Point out the error in the following program.

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

int main(){ char str1[] = "Learn through IndiaBIX\0.com", str2[120]; char *p; p = (char*) memccpy(str2, str1, 'i', strlen(str1)); *p = '\0'; printf("%s", str2); return 0;}

A.Error: in memccpy statement

Page 103: C Programming Test

B.Error: invalid pointer conversion

C.Error: invalid variable declaration

D.No error and prints "Learn through Indi"

Answer: Option D

Explanation:

Declaration:void *memccpy(void *dest, const void *src, int c, size_t n); : Copies a block of n bytes from src to dest

With memccpy(), the copying stops as soon as either of the following occurs:=> the character 'i' is first copied into str2=> n bytes have been copied into str2

Learn more problems on : Library Functions

Discuss about this problem : Discuss in Forum 20.Point out the error in the following program.

#include<stdio.h>

int main(){ char str[] = "IndiaBIX"; printf("%.#s %2s", str, str); return 0;}

A.Error: in Array declaration

B.Error: printf statement

C.Error: unspecified character in printf

D.No error

Answer: Option D

Learn more problems on : Library Functions

Discuss about this problem : Discuss in Forum 1. Point out the correct statements are correct about the program below?

#include<stdio.h>int main(){ char ch; while(x=0;x<=255;x++) printf("ASCII value of %d character %c\n", x, x);

Page 104: C Programming Test

return 0;}

A.The code generates an infinite loop

B.The code prints all ASCII values and its characters

C.Error: x undeclared identifier

D.Error: while statement missing

Answer: Option D

Explanation:

There are 2 errors in this program.1. "Undefined symbol x" error. Here x is not defined in the program.2. Here while() statement syntax error.

Learn more problems on : Control Instructions

Discuss about this problem : Discuss in Forum 2.Which of the following is the correct usage of conditional operators used in C?

A.a>b ? c=30 : c=40; B.a>b ? c=30;

C.max = a>b ? a>c?a:c:b>c?b:c D.return (a>b)?(a:b)

Answer: Option C

Explanation:

Option A: assignment statements are always return in paranthesis in the case of conditional operator. It should be a>b? (c=30):(c=40);

Option B: it is syntatically wrong.

Option D: syntatically wrong, it should be return(a>b ? a:b);

Option C: it uses nested conditional operator, this is logic for finding greatest number out of three numbers.

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum 3.What will be the output of the program?

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

Page 105: C Programming Test

float n=1.54; printf("%f, %f\n", ceil(n), floor(n)); return 0;}

A.2.000000, 1.000000 B.1.500000, 1.500000

C.1.550000, 2.000000 D.1.000000, 2.000000

Answer: Option A

Explanation:

ceil(x) round up the given value. It finds the smallest integer not < x.floor(x) round down the given value. It finds the smallest integer not > x.

printf("%f, %f\n", ceil(n), floor(n)); In this line ceil(1.54) round up the 1.54 to 2 and floor(1.54) round down the 1.54 to 1.

In the printf("%f, %f\n", ceil(n), floor(n)); statement, the format specifier "%f %f" tells output to be float value. Hence it prints 2.000000 and 1.000000.

Learn more problems on : Floating Point Issues

Discuss about this problem : Discuss in Forum 4.What will be the output of the program?

#include<stdio.h>int main(){ float d=2.25; printf("%e,", d); printf("%f,", d); printf("%g,", d); printf("%lf", d); return 0;}

A.2.2, 2.50, 2.50, 2.5

B.2.2e, 2.25f, 2.00, 2.25

C.2.250000e+000, 2.250000, 2.25, 2.250000

D.Error

Answer: Option C

Explanation:

printf("%e,", d); Here '%e' specifies the "Scientific Notation" format. So, it prints the 2.25 as 2.250000e+000.

Page 106: C Programming Test

printf("%f,", d); Here '%f' specifies the "Decimal Floating Point" format. So, it prints the 2.25 as 2.250000.

printf("%g,", d); Here '%g' "Use the shorter of %e or %f". So, it prints the 2.25 as 2.25.

printf("%lf,", d); Here '%lf' specifies the "Long Double" format. So, it prints the 2.25 as 2.250000.

Learn more problems on : Floating Point Issues

Discuss about this problem : Discuss in Forum 5.If a function contains two return statements successively, the compiler will generate warnings.

Yes/No ?A.Yes B.No

Answer: Option A

Explanation:

Yes. If a function contains two return statements successively, the compiler will generate "Unreachable code" warnings.

Example:

#include<stdio.h>int mul(int, int); /* Function prototype */

int main(){ int a = 4, b = 3, c; c = add(a, b); printf("c = %d\n", c); return 0;}int mul(int a, int b){ return (a * b); return (a - b); /* Warning: Unreachable code */}

Output:c = 12

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum 6.Point out the error in the program

Page 107: C Programming Test

#include<stdio.h>

int main(){ int i; #if A printf("Enter any number:"); scanf("%d", &i); #elif B printf("The number is odd"); return 0;}

A.Error: unexpected end of file because there is no matching #endif

B.The number is odd

C.Garbage values

D.None of above

Answer: Option A

Explanation:

The conditional macro #if must have an #endif. In this program there is no #endif statement written.

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum 7.What will be the output of the program ?

#include<stdio.h>

int main(){ float arr[] = {12.4, 2.3, 4.5, 6.7}; printf("%d\n", sizeof(arr)/sizeof(arr[0])); return 0;}

A.5 B.4

C.6 D.7

Answer: Option B

Explanation:

The sizeof function return the given variable. Example: float a=10; sizeof(a) is 4 bytes

Step 1: float arr[] = {12.4, 2.3, 4.5, 6.7}; The variable arr is declared as an floating point array

Page 108: C Programming Test

and it is initialized with the values.

Step 2: printf("%d\n", sizeof(arr)/sizeof(arr[0]));

The variable arr has 4 elements. The size of the float variable is 4 bytes.

Hence 4 elements x 4 bytes = 16 bytes

sizeof(arr[0]) is 4 bytes

Hence 16/4 is 4 bytes

Hence the output of the program is '4'.

Learn more problems on : Arrays

Discuss about this problem : Discuss in Forum 8.Is there any difference int the following declarations?

int fun(int arr[]);int fun(int arr[2]);

A.Yes B.No

Answer: Option B

Explanation:

No, both the statements are same. It is the prototype for the function fun() that accepts one integer array as an parameter and returns an integer value.

Learn more problems on : Arrays

Discuss about this problem : Discuss in Forum 9.What will be the output of the program (Turbo C in 16 bit platform DOS) ?

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

int main(){ char *str1 = "India"; char *str2 = "BIX"; char *str3; str3 = strcat(str1, str2); printf("%s %s\n", str3, str1); return 0;}

A.IndiaBIX India B.IndiaBIX IndiaBIX

Page 109: C Programming Test

C.India India D.Error

Answer: Option B

Explanation:

It prints 'IndiaBIX IndiaBIX' in TurboC (in 16 bit platform).

It may cause a 'segmentation fault error' in GCC (32 bit platform).

Learn more problems on : Strings

Discuss about this problem : Discuss in Forum 10.Which of the following statements correct about the below program?

#include<stdio.h>

int main(){ union a { int i; char ch[2]; }; union a u1 = {512}; union a u2 = {0, 2}; return 0;}1: u2 CANNOT be initialized as shown.2: u1 can be initialized as shown.3: To initialize char ch[] of u2 '.' operator should be used.4: The code causes an error 'Declaration syntax error'

A.1, 2 B.2, 3

C.1, 2, 3 D.1, 3, 4

Answer: Option C

Learn more problems on : Structures, Unions, Enums

Discuss about this problem : Discuss in Forum 11.Does there exist any way to make the command-line arguments available to other functions

without passing them as arguments to the function?A.Yes B.No

Answer: Option A

Page 110: C Programming Test

Explanation:

Using the predefined variables _argc, _argv. This is a compiler dependent feature. It works in TC/TC++ but not in gcc and visual studio.

Learn more problems on : Command Line Arguments

Discuss about this problem : Discuss in Forum 12.What will be the output of the program?

#include<stdio.h>int get();

int main(){ const int x = get(); printf("%d", x); return 0;}int get(){ return 20;}

A.Garbage value B.Error

C.20 D.0

Answer: Option C

Explanation:

Step 1: int get(); This is the function prototype for the funtion get(), it tells the compiler returns an integer value and accept no parameters.

Step 2: const int x = get(); The constant variable x is declared as an integer data type and initialized with the value "20".

The function get() returns the value "20".

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

Hence the output of the program is "20".

Learn more problems on : Const

Discuss about this problem : Discuss in Forum 13.Point out the error in the program.

#include<stdio.h>

Page 111: C Programming Test

#include<stdlib.h>int fun(const union employee *e);

union employee{ char name[15]; int age; float salary;};const union employee e1;

int main(){ strcpy(e1.name, "A"); fun(&e1); printf("%s %d %f", e1.name, e1.age, e1.salary); return 0;}int fun(const union employee *e){ strcpy((*e).name, "B"); return 0;}

A.Error: RValue required

B.Error: cannot convert parameter 1 from 'const char[15]' to 'char *'

C.Error: LValue required in strcpy

D.No error

Answer: Option B

Learn more problems on : Const

Discuss about this problem : Discuss in Forum 14.What function should be used to free the memory allocated by calloc() ?

A.dealloc(); B.malloc(variable_name, 0)

C.free(); D.memalloc(variable_name, 0)

Answer: Option C

Learn more problems on : Memory Allocation

Discuss about this problem : Discuss in Forum 15.Point out the correct statement which correctly free the memory pointed to by 's' and 'p' in the

following program?

#include<stdio.h>#include<stdlib.h>

int main(){

Page 112: C Programming Test

struct ex { int i; float j; char *s }; struct ex *p; p = (struct ex *)malloc(sizeof(struct ex)); p->s = (char*)malloc(20); return 0;}

A.free(p); , free(p->s); B.free(p->s); , free(p);

C.free(p->s); D.free(p);

Answer: Option B

Learn more problems on : Memory Allocation

Discuss about this problem : Discuss in Forum 16.What do the following declaration signify?

void *cmp();

A. cmp is a pointer to an void type.

B. cmp is a void type pointer variable.

C. cmp is a function that return a void pointer.

D. cmp function returns nothing.

Answer: Option C

Learn more problems on : Complicated Declarations

Discuss about this problem : Discuss in Forum 17.What will be the output of the program?

#include<stdio.h>

int main(){ 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, 4 B.2, 2, 2

C.2, 8, 4 D.2, 4, 8

Page 113: C Programming Test

Answer: Option A

Learn more problems on : Complicated Declarations

Discuss about this problem : Discuss in Forum 18.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)();}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 19.We can modify the pointers "source" as well as "target".

A.True B.False

Answer: Option A

Learn more problems on : Complicated Declarations

Discuss about this problem : Discuss in Forum 20.Will the program outputs "IndiaBIX.com"?

#include<stdio.h>

Page 114: C Programming Test

#include<string.h>

int main(){ char str1[] = "IndiaBIX.com"; char str2[20]; strncpy(str2, str1, 8); printf("%s", str2); return 0;}

A.Yes B.No

Answer: Option B

Explanation:

No. It will print something like 'IndiaBIX(some garbage values here)' .

Because after copying the first 8 characters of source string into target string strncpy() doesn't terminate the target string with a '\0'. So it may print some garbage values along with IndiaBIX.

Learn more problems on : Library Functions

Discuss about this problem : Discuss in Forum