You are on page 1of 47

c 



      

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

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

       


#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. 1, 2, 0, 1 B. -3, 2, 0, 1
C. -2, 3, 0, 1 D. 2, 3, 1, 1

  : 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".
]       
#include<stdio.h>
int fun(int, int);
typedef int (*pf) (int, int);
int proc(pf, int, int);

int main()
{
printf("%d\n", proc(fun, 6, 6));
return 0;
}
int fun(int a, int b)
{
return (a==b);
}
int proc(pf p, int a, int b)
{
return ((*p)(a, b));
}
A. 6 B. 1
C. 0 D. -1

  : Option B

       


#include<stdio.h>
#define FUN(arg) do\
{\
if(arg)\
printf("IndiaBIX...", "\n");\
}while(--i)

int main()
{
int i=2;
FUN(i<3);
return 0;
}
A. IndiaBIX...
IndiaBIX...
IndiaBIX

B. IndiaBIX... IndiaBIX...

C. Error: cannot use control instructions in macro

D. No output

  : Option B
Explanation:
The macro FUN(arg) prints the statement "IndiaBIX..." untill the while condition is satisfied.

Step 1: int i=2; The variable i is declared as an integer type and initialized to 2.

Step 2: FUN(i<3); becomes,

do
{
if(2 < 3)
printf("IndiaBIX...", "\n");
}while(--2)

After the 2 while loops the value of i becomes '0'(zero). Hence the while loop breaks.
Hence the output of the program is "IndiaBIX... IndiaBIX..."

r       


#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;
}
A. 8 B. 9
C. 6 D. 5

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

       


#include<stdio.h>
#define MAX(a, b, c) (a>b ? a>c ? a : c: b>c ? b : c)
int main()
{
int x;
x = MAX(3+2, 2+7, 3+7);
printf("%d\n", x);
return 0;
}
A. 5 B. 9
C. 10 D. 3+7

  : Option C
Explanation:
The macro MAX(a, b, c) (a>b ? a>c ? a : c: b>c ? b : c) returns the biggest of given three
numbers.

Step 1: int x; The variable x is declared as an integer type.


Step 2: x = MAX(3+2, 2+7, 3+7); becomes,

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

=> x = (5 >9 ? (5 > 10 ? 5 : 10): (9 > 10 ? 9 : 10) )

=> x = (5 >9 ? (10): (10) )

=> x = 10

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


Hence the output of the program is "10".

       


#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

  : Option B
×           

  
 
 
       
#include<stdio.h>
void fact(int*);

int main()
{
int i=5, j;
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;

  : Option B

!   "#$$        


A. Yes B. No

  : Option B

c%          &     r×


#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

  : 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

cc        


#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

  : Option C
Explanation:

Step 1: char str1[20] = "Hello", str2[20] = " World"; The variable str1 and str2 is declared 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".

c  '        (]   (]  


   


 
char arr[] = "IndiaBIX";
char *ptr = "IndiaBIX";
A. Yes B. No

  ) Option A
Explanation:

Yes, both the statements prints the same character 'i'.

c]     


   &   
 
A. True B. False

  : Option B

c  * 
  +   
& 
  &
A. Yes B. No
  : Option B

cr        


#include<stdio.h>
#include<stdarg.h>
void fun1(int num, ....);
void fun2(int num, ....);

int main()
{
fun1(1, "Apple", "Boys", "Cats", "Dogs");
fun2(2, 12, 13, 14);
return 0;
}
void fun1(int num, ...)
{
char *str;
va_list ptr;
va_start(ptr, num);
str = va_arg(ptr, char *);
printf("%s", str);
}
void fun2(int num, ...)
{
va_list ptr;
va_start(ptr, num);
num = va_arg(ptr, int);
printf("%d", num);
}
A. Dogs 12 B. Cats 14
C. Boys 13 D. Apple 12

  : Option D

c         
#include<stdio.h>
#include<stdarg.h>
void display(char *s, ...);
void show(char *t, ...);

int main()
{
display("Hello", 4, 12, 13, 14, 44);
return 0;
}
void display(char *s, ...)
{
show(s, ...);
}
void show(char *t, ...)
{
int a;
va_list ptr;
va_start(ptr, s);
a = va_arg(ptr, int);
printf("%f", a);
}
A. Error: invalid function display() call

B. Error: invalid function show() call

C. No error

D. Error: Rvalue required for t

  ) Option B

Explanation:
The call to show() is improper. This is not the way to pass variable argument list to a function.

c   
 
, ,        - 
    

        
A. True
B. False

  : Option B

c×        


#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, 4, 4
C. 4, 4, 2 D. 2, 4, 8

  : Option A

c!        


#include<stdio.h>

int main()
{
char huge *near *ptr1;
char huge *far *ptr2;
char huge *huge *ptr3;
printf("%d, %d, %d\n", sizeof(ptr1), sizeof(ptr2), sizeof(ptr3));
return 0;
}
A. 4, 4, 8 B. 2, 4, 4
C. 4, 4, 2 D. 2, 4, 8

  : Option B

%       
         
A. True B. False

  ) Option A

Explanation:

The ftell() function shall obtain the current value of the file-position indicator for the stream
pointed to by stream.

Example:

#include <stdio.h>

int main(void)
{
FILE *stream;
stream = fopen("MYFILE.TXT", "w+");
fprintf(stream, "This is a test");
printf("The file pointer is at byte %ld\n", ftell(stream));
fclose(stream);
return 0;
}
c 
   &  * 
1. !
2. sizeof
3. ~
4. &&

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

  ) Option D

.-  )

An operation with only one operand is called unary operation.


Unary operators:
! Logical NOT operator.
~ bitwise NOT operator.
sizeof Size-of operator.

&& Logical AND is a logical operator.

Therefore, 1, 2, 3 are unary operators.

 /     &  ,   


 ,& 
A. Yes B. No

  : Option B

Explanation:

No, Two different operators may have same associativity.

Example:
Arithmetic operators like ++, -- having Right-to-Left associativity.
Relational operators like >, >= also have Left-to-Right associativity.

]   - 01
   & 
 
A. Yes B. No

  ) Option B

Explanation:
Because, here even though the value of p is accessed twice it is used to modify two different
objects p and *p

  &  
  ] c   
A. use 3.14LD B. use 3.14L
C. use 3.14DL D. use 3.14LF
  ) Option B

Explanation:

Given 3.14 is a double constant.

To specify 3.14 as long double, we have to add L to the 3.14. (i.e 3.14L)

r   
 
, 2 
  & 
   
2    
A. True B. False

  ) 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

       


#include<stdio.h>

void fun(void *p);


int i;

int main()
{
void *vptr;
vptr = &i;
fun(vptr);
return 0;
}
void fun(void *p)
{
int **q;
q = (int**)&p;
printf("%d\n", **q);
}
A. Error: cannot convert from void** to int** B. Garbage value
C. 0 D. No output

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

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

× /  &
  ,     
A. strstr() B. strrev()
C. revstr() D. strreverse()

  ) 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

! 
 
          3
   
A. printf(); B. scanf();
C. gets(); D. puts();

  ) Option C

Explanation:

gets(); collects a string of characters terminated by a new line from the standard input stream
stdin
#include <stdio.h>

int main(void)
{
char string[80];

printf("Enter a string:");
gets(string);
printf("The string input was: %s\n", string);
return 0;
}

Output:

Enter a string: IndiaBIX

The string input was: IndiaBIX

c%  4     



    
A. gets() B. fgets()

  : Option B

Explanation:
Because, In fgets() we can specify the size of the buffer into which the string supplied will be
stored.

cc        


#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

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

c  
        

5    
  
 
A. && operator B. & operator
C. || operator D. ! operator

  ) Option B

c]        


#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

  : Option A

c     & 
 2   &   
 
typedef char * string_t;
#define string_d char *;
string_t s1, s2;
string_d s3, s4;
A. Yes
B. No

  ) Option A

Explanation:
In these declarations, s1, s2 and s3 are all treated as char*, but s4 is treated as a char, which is
probably not the intention.
cr       6  -6&     
typedef unsigned long int uli;
uli i, j;
unsigned long int x, y;
A. Yes
B. No

  : Option A

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

B. Error: invalid array string

C. None of above

D. No error. It prints A A

  )Option D

Explanation:

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

c   

    


&    & 
&7 7 77   
#include<stdio.h>
#include<stdlib.h>

int main()
{
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);

  : Option B

c×        


#include<stdio.h>
#include<stdarg.h>
void fun(char *msg, ....);

int main()
{
fun("IndiaBIX", 1, 4, 7, 11, 0);
return 0;
}
void fun(char *msg, ....)
{
int tot=0;
va_list ptr;
int num;
va_start(ptr, msg);
num = va_arg(ptr, int)
num = va_arg(ptr, int)
printf("%d", num);
}

A. IndiaBIX 1 7 11 0 B. 1
C. 4 D. 7

  : Option C

c!        
#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.

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

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

% 
  

  
,    5 8]8
  .
A. Yes B. No

  ) Option A

Explanation:

scanf is a function that reads data with specified format from a given string stream source.
scanf("%d",&number);

atoi() convert string to integer.


var number;
number = atoi("string");
c    6 &    
#include<stdio.h>
int main()
{
int i = 1;
switch(i)
{
case 1:
printf("Case1");
break;
case 1*2+4:
printf("Case2");
break;
}
return 0;
}
A. Error: in case 1*2+4 statement

B. Error: No default specified

C. Error: in switch statement

D. No Error

  : Option D

Explanation:

Constant expression are accepted in switch

It prints "Case1"

          


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

A. Yes B. No

  : 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;
}
else
{
c = 30;
}

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

if(a <= 20)


{
//Nothing here
}
else
{
c = 30;
}

] 9

  

  5 -
&  &.
A. True B. False

  : Option B

Explanation:

False, A macro just replaces each occurrence with the code assigned to it. e.g. SQUARE(3) with
((3)*(3)) in the program.

A function is compiled once and can be called from anywhere that has visibility to the funciton.

       


#include<stdio.h>

int main()
{
char str[20] = "Hello";
char *const p=str;
*p='M';
printf("%s\n", str);
return 0;
}
A. Mello
B. Hello

C. HMello
D. MHello

  ) Option A

r       


#include<stdio.h>
int main()
{
printf("%c\n", 7["IndiaBIX"]);
return 0;
}
A. Error: in printf
B. Nothing will print

C. print "X" of IndiaBIX


D. print "7"

  : Option C

           


 
 
       
#include<stdio.h>
int main()
{
int *j;
void fun(int**);
fun(&j);
return 0;
}
void fun(int **k)
{
int a=10;
/* Add a statement here */
}
A. **k=a;
B. k=&a;

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

  ) Option C

       


#include<stdio.h>

int main()
{
static int arr[] = {0, 1, 2, 3, 4};
int *p[] = {arr, arr+1, arr+2, arr+3, arr+4};
int **ptr=p;
ptr++;
printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
*ptr++;
printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
*++ptr;
printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
++*ptr;
printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
return 0;
}
A. 0, 0, 0
1, 1, 1
2, 2, 2
3, 3, 3
B. 1, 1, 2
2, 2, 3
3, 3, 4
4, 4, 1

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

  : Option C

×       


#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
  )Option B

!       


#include<stdio.h>

int main()
{
struct a
{
category:5;
scheme:4;
};
printf("size=%d", sizeof(struct a));
return 0;
}
A. Error: invalid structure member in printf

B. Error: bit field type must be signed int or unsigned int

C. No error

D. None of above

  ) Option B

c%        


#include<stdio.h>

int main()
{
struct bits
{
float f:2;
}bit;

printf("%d\n", sizeof(bit));
return 0;
}
A. 4

B. 2

C. Error: cannot set bit field for float

D. Error: Invalid member access in structure

  ) Option C
cc   *""4/ 
 
A. Yes
B. No

  ) Option B

c   
  5
typedef struct s
{
int a;
float b;
}s;
A. Yes
B. No

  ) Option A

c]  *    
 
 
A. Yes
B. No

  ) Option A

Explanation:
A structure pointing to itself is called self-referential structures.

c  :&    


& 
    
  
#include<stdio.h>

int main()
{
char ch, str[10];
while((ch=getc(stdin))!= EOF)
putc(ch, stdout);
return 0;
}
A. mycopy > sourcefile > targetfile

B. mycopy < sourcefile > targetfile

C. mycopy > sourcefile < targetfile

D. mycopy < sourcefile < targetfile


  : Option B

Explanation:

Compile this file and it makes the mycopy.exe file.

Open the command prompt and type

mycopy <source.txt> target.txt

The contents of the source.txt is copied in to target.txt

cr              , 



 6 5  
A. True
B. False

  ) Option A

Explanation:

True, we should not be able to read a file after writing in that file without calling the below
functions.

int fflush ( FILE * stream ); If the given stream was open for writing and the last i/o operation
was an output operation, any unwritten data in the output buffer is written to the file.

int fseek ( FILE * stream, long int offset, int origin ); Its purpose is to change the file position
indicator for the specified stream.

void rewind ( FILE * stream ); Sets the position indicator associated with stream to the
beginning of the file.

c  
  &  
  & c%cc%ccccc%%%c%c 
&
,  
A. Decimal system
B. Hexadecimal system

C. Octal system
D. No need to convert

  ) Option B

Explanation:
Hexadecimal system is better, because each 4-digit binary represents one Hexadecimal digit.

c        


#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

  ) Option B

c×        


#include<stdio.h>

int main()
{
enum color{red, green, blue};
typedef enum color mycolor;
mycolor m = red;
printf("%d", m);
return 0;
}
A. 1
B. 0

C. 2
D. red

  ) Option B

c!     ,      


       
A. Yes
B. No

  ) Option A

%        


#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

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

  ) Option C
c       
#include<stdio.h>
int main()
{
int a = 500, b = 100, c;
if(!a >= 400)
b = 300;
c = 200;
printf("b = %d c = %d\n", b, c);
return 0;
}
A. b = 300 c = 200
B. b = 100 c = garbage

C. b = 300 c = garbage
D. b = 100 c = 200

  ) Option D

Explanation:

Initially variables a = 500, b = 100 and c is not assigned.

Step 1: if(!a >= 400)


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

       


#include<stdio.h>
int check (int, int);

int main()
{
int c;
c = check(10, 20);
printf("c=%d\n", c);
return 0;
}
int check(int i, int j)
{
int *p, *q;
p=&i;
q=&j;
i>=45 ? return(*p): return(*q);
}
A. Print 10
B. Print 20

C. Print 1
D. Compile error

  : Option D

Explanation:

There is an error in this line i>=45 ? return(*p): return(*q);. We cannot use return keyword in
the terenary operators.

]       


#include<stdio.h>
#define SI(p, n, r) float si; si=p*n*r/100;
int main()
{
float p=2500, r=3.5;
int n=3;
SI(p, n, r);
SI(1500, 2, 2.5);
return 0;
}
A. 26250.00 7500.00
B. Nothing will print

C. Error: Multiple declaration of si


D. Garbage values

  ) Option C

Explanation:

The macro #define SI(p, n, r) float si; si=p*n*r/100; contains the error. To remove this error, we
have to modify this macro to

#define SI(p,n,r) p*n*r/100

   
 
,          
  
 
A. True
B. False
  ) Option A

Explanation:

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

r    
  
 6  
 
  

 & 
A. True
B. False

  ) Option A

Explanation:

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

       


#include<stdio.h>

int main()
{
void fun(int, int[]);
int arr[] = {1, 2, 3, 4};
int i;
fun(4, arr);
for(i=0; i<4; i++)
printf("%d,", arr[i]);
return 0;
}
void fun(int n, int arr[])
{
int *p=0;
int i=0;
while(i++ < n)
p = &arr[i];
*p=0;
}
A. 2, 3, 4, 5
B. 1, 2, 3, 4

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

  ) Option B
Explanation:

Step 1: void fun(int, int[]); This prototype tells the compiler that the function fun() accepts one
integer value and one array as an arguments and does not return anything.

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

a[0] = 1, a[1] = 2, a[2] = 3, a[3] = 4

Step 3: int i; The variable i is declared as an integer type.

Step 4: fun(4, arr); This function does not affect the output of the program. Let's skip this
function.

Step 5: for(i=0; i<4; i++) { printf("%d,", arr[i]); } The for loop runs untill the variable i is less
than '4' and it prints the each value of array a.

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

       


#include<stdio.h>

int main()
{
char t;
char *p1 = "India", *p2;
p2=p1;
p1 = "BIX";
printf("%s %s\n", p1, p2);
return 0;
}
A. India BIX
B. BIX India

C. India India
D. BIX BIX

  ) Option B

Explanation:

Step 1: char *p1 = "India", *p2; The variable p1 and p2 is declared as an pointer to a character
value and p1 is assigned with a value "India".

Step 2: p2=p1; The value of p1 is assigned to variable p2. So p2 contains "India".

Step 3: p1 = "BIX"; The p1 is assigned with a string "BIX"

Step 4: printf("%s %s\n", p1, p2); It prints the value of p1 and p2.
Hence the output of the program is "BIX India".

×       


#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

  : Option B

!       


#include<stdio.h>

int main()
{
struct emp
{
char name[25];
int age;
float bs;
};
struct emp e;
e.name = "Suresh";
e.age = 25;
printf("%s %d\n", e.name, e.age);
return 0;
}
A. Error: Lvalue required

B. Error: invalid structure assignment


C. Error: Rvalue required

D. No error

  ) Option A

c%    7
7 7,7 ,    
A. 'c' means argument control 'v' means argument vector

B. 'c' means argument count 'v' means argument vertex

C. 'c' means argument count 'v' means argument vector

D. 'c' means argument configuration 'v' means argument visibility

  : Option C

cc  
       

    
#include<stdio.h>

int main()
{
unsigned int num;
int i;
scanf("%u", &num);
for(i=0; i&lt16; 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

  ) Option C

c        


#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

  ) Option B

c]        


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

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

int main()
{
strcpy(e1.name, "K");
printf("%s %d %f", e1.name, e1.age, e1.salary);
return 0;
}
A. Error: RValue required

B. Error: cannot convert from 'const int *' to 'int *const'

C. Error: LValue required in strcpy

D. No error

  : Option D

Explanation:

The output will be:


K 75 0.000000

c         
#include<stdio.h>
#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

  ) Option B

cr  :&    & 


 &   
#include<stdio.h>
#include<stdlib.h>
#define MAXROW 3
#define MAXCOL 4

int main()
{
int **p, i, j;
p = (int **) malloc(MAXROW * sizeof(int*));
return 0;
}
A. memfree(int p);
B. dealloc(p);

C. malloc(p, 0);
D. free(p);

  ) Option D

c   
        &  
     7  
    &  
     7 
A. True
B. False

  ) Option B

c        


#include<stdio.h>
#include<stdarg.h>
void display(int num, ....);

int main()
{
display(4, 'A', 'B', 'C', 'D');
return 0;
}
void display(int num, ...)
{
char c, c1; int j;
va_list ptr, ptr1;
va_start(ptr, num);
va_start(ptr1, num);
for(j=1; j<=num; j++)
{
c = va_arg(ptr, int);
printf("%c", c);
c1 = va_arg(ptr1, int);
printf("%d\n", c1);
}
}
A. A, A
B, B
C, C
D, D
B. A, a
B, b
C, c
D, d

C. A, 65
B, 66
C, 67
D, 68
D. A, 0
B, 0
C, 0
C, 0

  ) Option C

c×  / 
, ;    -
     - 

    , 
    -   
A. Yes
B. No

  ) Option B

c!  <
      
"A pointer to an array of three chars".
A. char *ptr[3]();
B. char (*ptr)*[3];

C. char (*ptr[3])();
D. char (*ptr)[3];

  : Option D

%    
    
char far *far *scr;
char far far** scr;
A. Yes
B. No

  ) Option B
c 
       

    
#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

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

 /    
    
A. True
B. False

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

] 
 

&   
&  

  *
A. /+*-
B. *-/+
C. +-/*
D. /*+-

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

       


#include<stdio.h>

int main()
{
void fun(char*);
char a[100];
a[0] = 'A'; a[1] = 'B';
a[2] = 'C'; a[3] = 'D';
fun(&a[0]);
return 0;
}
void fun(char *a)
{
a++;
printf("%c", *a);
a++;
printf("%c", *a);
}
A. AB
B. BC

C. CD
D. No output

  ) Option B

r   +    &       


#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

  ) Option B

       


#include<stdio.h>

int main()
{
printf(5+"Good Morning\n");
return 0;
}
A. Good Morning
B. Good

C. M
D. Morning

  : Option D

Explanation:

printf(5+"Good Morning\n"); It skips the 5 characters and prints the given string.

Hence the output is "Morning"

       



 7 7677 7
7   
  
#include<stdio.h>

int main()
{
void fun();
fun();
printf("\n");
return 0;
}
void fun()
{
char c;
if((c = getchar())!= '\n')
fun();
printf("%c", c);
}
A. abc abc
B. bca

C. Infinite loop
D. cba

  ) Option D

Explanation:

Step 1: void fun(); This is the prototype for the function fun().

Step 2: fun(); The function fun() is called here.

The function fun() gets a character input and the input is terminated by an enter key(New line
character). It prints the given character in the reverse order.

The given input characters are "abc"

Output: cba

× 
       

     
#include<stdio.h>

int main()
{
char str[20], *s;
printf("Enter a string\n");
scanf("%s", str);
s=str;
while(*s != '\0')
{
if(*s >= 97 && *s <= 122)
*s = *s-32;
s++;
}
printf("%s",str);
return 0;
}
A. The code converts a string in to an integer

B. The code converts lower case character to upper case


C. The code converts upper case character to lower case

D. Error in code

  : Option B

Explanation:

This program converts the given string to upper case string.

Output:

Enter a string: indiabix

INDIABIX

!       


#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

  ) Option A

c%    7 
-7
    8= &  8
 
     
#include<stdio.h>

int main()
{
FILE *fs, *ft;
char c[10];
fs = fopen("source.txt", "r");
c = 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();

  ) Option C

Explanation:

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

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

fseek(fs, -3L, SEEK_CUR); moves the file pointer backward by 3 characters.

fgets(c, 5, fs); read the file from the current position of the file pointer.

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

Therefore, it prints "end".

cc        


#include<stdio.h>

int main()
{
FILE *fp;
fp=fopen("trial", "r");
fseek(fp, 20, SEEK_SET);
fclose(fp);
return 0;
}
A. Error: unrecognised Keyword SEEK_SET

B. Error: fseek() long offset value

C. No error
D. None of above

  ) Option B

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

c        & 


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

  )Option B

c]         


,   
-
   
  
cmd> sample 1 2 3
/* sample.c */
#include<stdio.h>

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


{
int j;
j = argv[1] + argv[2] + argv[3];
printf("%d", j);
return 0;
}
A. 6
B. sample 6

C. Error
D. Garbage value
  ) Option C

c         


,   
-
   
  
cmd> sample friday tuesday sunday
/* sample.c */
#include<stdio.h>

int main(int sizeofargv, char *argv[])


{
while(sizeofargv)
printf("%s", argv[--sizeofargv]);
return 0;
}
A. sample friday tuesday sunday

B. sample friday tuesday

C. sunday tuesday friday sample

D. sunday tuesday friday

  ) Option C

cr  
       

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

D. It converts a number to its equivalent octal.

  ) Option A

c         
#include<stdio.h>
#define MAX 128

int main()
{
char mybuf[] = "India";
char yourbuf[] = "BIX";
char const *ptr = mybuf;
*ptr = 'a';
ptr = yourbuf;
return 0;
}
A. Error: cannot convert ptr const value

B. Error: unknown pointer conversion

C. No error

D. None of above

  : Option A

Explanation:

Step 1: char mybuf[] = "India"; The variable mybuff is declared as an array of characters and
initialized with string "India".

Step 2: char yourbuf[] = "BIX"; The variable yourbuf is declared as an array of characters and
initialized with string "BIX".

Step 3: char const *ptr = mybuf; Here, ptr is a constant pointer, which points at a char.

The value at which ptr it points is a constant; it will be an error to modify the pointed character;
There will not be any error to modify the pointer itself.
Step 4: *ptr = 'a'; Here, we are changing the value of ptr, this will result in the error "cannot
modify a const object".

c  <
      
"An array of three pointers to chars".
A. char *ptr[3]();
B. char *ptr[3];

C. char (*ptr[3])();
D. char **ptr[3];

  ) Option B

c×    
  &
int *f();
A. f is a pointer variable of function type.

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.

  ) Option B

c!        


#include<stdio.h>
typedef unsigned long int uli;
typedef uli u;

int main()
{
uli a;
u b = -1;
a = -1;
printf("%lu, %lu"a, b);
return 0;
}
A. 4343445454, 4343445454
B. 4545455434, 4545455434

C. 4294967295, 4294967295
D. Garbage values

  ) Option C
%  * &     &  

A. Yes
B. No

  ) Option A

Explanation:
Do like this fprintf(stdout, "%s %d %f", str, i, a);

You might also like