Вы находитесь на странице: 1из 30

1.

What will be the output of the program?

#include<stdio.h>
int main()
{
typedef float f;
static f *fptr;
float fval = 90;
fptr = &fval;
printf("%f\n", *fptr);
return 0;
}

A.

B.

C.

90.000000

D.

90

Answer: Option C
Learn more problems on : Typedef
Discuss about this problem : Discuss in Forum
2.
Which of the following statements are correct about the program?

#include<stdio.h>
int main()
{
unsigned int num;
int i;
scanf("%u", &num);
for(i=0; i<16; i++)
{
printf("%d", (num<<i & 1<<15)?1:0);
}
return 0;
}

A.

It prints all even bits from num

B.

It prints all odd bits from num

C.

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

3.
What will be the output of the program?

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

A.

Hello
Hi

B.

Hello
Bye

C.

Hi

D.

Bye

Answer: Option C
Explanation:

switch(i) has the variable i it has the value '1'(one).


Then case 1: statements got executed. so, it prints "Hi". The break; statement make the
program to be exited from switch-case statement.

switch-case do not execute any statements outside these blocks case and default
Hence the output is "Hi".
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 get();
int main()
{
const int x = get();
printf("%d", x);
return 0;
}
int get()
{
return 20;
}

A.

Garbage value

B.

Error

C.

20

D.

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

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

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

7.
What will be the output of the program?

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

{
char *z;
int i;
struct s1 *p;
};
static struct s1 a[] = {{"Nagpur", 1, a+1} , {"Chennai", 2, a+2} ,
{"Bangalore", 3, a} };
struct s1 *ptr = a;
printf("%s,", ++(ptr->z));
printf("%s,", a[(++ptr)->i].z);
printf("%s", a[--(ptr->p->i)].z);
return 0;
}

A.

Nagpur, Chennai, Bangalore

B.

agpur, hennai, angalore

C.

agpur, Chennai, angalore

D.

agpur, Bangalore, Bangalore

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

8.
What will the function rewind() do?

A.

Reposition the file pointer to a character reverse.

B.

Reposition the file pointer stream to end of file.

C.

Reposition the file pointer to begining of that line.

D.

Reposition the file pointer to begining of file.

Answer: Option D
Explanation:

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

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

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

B.

No

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

11.
Every function must return a value

A.

Yes

Answer: Option B
Explanation:
No, If a function return type is declared as void it cannot return any value.
Learn more problems on : Functions
Discuss about this problem : Discuss in Forum

12.
In a function two return statements should never occur.

A.

Yes

B.

No

Answer: Option B
Explanation:
No, In a function two return statements can occur but not successively.
Example:

#include<stdio.h>
int mul(int, int); /*Functionprototype*/
int main()

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

}
/*Tworeturnstatementsinthemul()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

13.
What will be the output of the program?

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

A.

40 40

B.

20 40

C.

20

D.

Error

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

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

A.

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

B.

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

C.

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

D.

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

Answer: Option B
Learn more problems on : Pointers
Discuss about this problem : Discuss in Forum

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

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

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

A.

&& operator

B.

& operator

C.

|| operator

D.

! operator

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

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

A.

* (asterisk)

B.

| (pipeline)

C.

- (hyphen)

D.

_ (underscore)

Answer: Option D
Explanation:
Variable names in C are made up of letters (upper and lower case) and digits. The underscore
character ("_") is also permitted. Names must not begin with a digit.
Examples of valid (but not very descriptive) C variable names:
=> foo
=> Bar
=> BAZ
=> foo_bar
=> _foo42
=> _
=> QuUx
Learn more problems on : Declarations and Initializations
Discuss about this problem : Discuss in Forum
19.
Point out the error, if any in the program.

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

int i = 1;
switch(i)
{
printf("Thisiscprogram.");
case 1:
printf("Case1");
break;
case 2:
printf("Case2");
break;
}
return 0;
}

A.

Error: No default specified

B.

Error: Invalid printf statement after switch statement

C.

No Error and prints "Case1"

D.

None of above

Answer: Option C
Explanation:

switch(i) becomes switch(1), then the case 1: block is get executed. Hence it prints
"Case1".

printf("This is c program."); is ignored by the compiler.


Hence there is no error and prints "Case1".
Learn more problems on : Control Instructions
Discuss about this problem : Discuss in Forum

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

A.

Yes

B.

No

Answer: Option A
Explanation:

string.h is the header in the C standard library for the C programming language which contains
macro definitions, constants, and declarations of functions and types used not only for string
handling but also various memory handling functions.
Learn more problems on : Library Functions
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=%dy=%d\n", x, y);
return 0;
}
1:

The printf() function is called 10 times.

2:

The program will produce the output x = 10 y = 10

3:

The ; after the if(x!=y) will NOT produce an error.

4:

The program will not produce output.


A.

B.

2, 3

C.

3, 4

D.

Answer: Option B

Learn more problems on : Control Instructions


Discuss about this problem : Discuss in Forum

2.
What will be the output of the program?

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

A.

200

B.

30

C.

100

D.

500

Answer: Option B
Explanation:
Step 1: int k, num=30; here variable k and num are declared as an integer type and
variable num is initialized to '30'.
Step 2: k = (num>5 ? (num <=10 ? 100 : 200): 500); This statement does not affect
the output of the program. Because we are going to print the variable num in the next statement.
So, we skip this statement.
Step 3: printf("%d\n", num); It prints the value of variable num '30'
Step 3: Hence the output of the program is '30'
Learn more problems on : Expressions
Discuss about this problem : Discuss in Forum

3.
Point out the error in the following program.

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

struct emp
{
char name[20];
float sal;
};
struct emp e[10];
int i;
for(i=0; i<=9; i++)
scanf("%s%f", e[i].name, &e[i].sal);
return 0;
}

A.

Suspicious pointer conversion

B.

Floating point formats not linked (Run time error)

C.

Cannot use scanf() for structures

D.

Strings cannot be nested inside structures

Answer: Option B
Explanation:
Compile and Run the above program in Turbo C:
C:\>myprogram.exe
Sundar
2555.50
scanf : floating point formats not linked
Abnormal program termination
The program terminates abnormally at the time of entering the float value for e[i].sal.
Solution:
Just add the following function in your program. It will force the compiler to include required
libraries for handling floating point linkages.
static void force_fpf() /* A dummy function */
{
float x, *y; /* Just declares two variables */
y = &x;
/* Forces linkage of FP formats */
x = *y;
/* Suppress warning message about x */

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

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

A.

switch

B.

goto

C.

go back

D.

return

Answer: Option D
Explanation:
The keyword return is used to transfer control from a function back to the calling function.
Example:

#include<stdio.h>
int add(int, int); /*Functionprototype*/
int main()

int a = 4, b = 3, c;

c = add(a, b);
printf("c=%d\n", c);
return 0;
}
int add(int a, int b)

{
/*returnsthevalueandcontrolbacktomain()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);
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.


A.

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[] = "IlearnthroughIndiaBIX.com";
char *ptr, c = 'i';

ptr = strrchr(text, c);


if (ptr)
printf("Thepositionof'%c'is:%d\n", c, ptr-text);
else

printf("Thecharacterwasnotfound\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

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

B.

False

Answer: Option A
Learn more problems on : Structures, Unions, Enums
Discuss about this problem : Discuss in Forum
13.
Bit fields CANNOT be used in union.

A.

True

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("\nThevalueofres=%d" , pt.res);
return 0;

}
//Output:Thevalueofres=3

Learn more problems on : Structures, Unions, Enums


Discuss about this problem : Discuss in Forum

14.
Which of the following statement is correct about the program?

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

A.

The code counts number of characters in the file

B.

The code counts number of words in the file

C.

The code counts number of blank lines in the file

D.

The code counts number of lines in the file

Answer: Option D
Explanation:
This program counts the number of lines in the file myfile.c by counting the character'\n' in
that file.
Learn more problems on : Input / Output
Discuss about this problem : Discuss in Forum

15.
The first argument to be supplied at command-line must always be count of total arguments.

A.

True

B.

False

B.

12480

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

C.

12500

D.

12556

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

17.
What is the output of the program?

typedef struct data;


{
int x;
sdata *b;
}sdata;

A.

Error: Declaration missing ';'

B.

Error: in typedef

C.

No error

D.

None of above

Answer: Option A
Explanation:
since the type 'sdata' is not known at the point of declaring the structure
Learn more problems on : Typedef
Discuss about this problem : Discuss in Forum

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

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.

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

False