C Question Set 1-7


Question 1

'C' is a

machine  language

low level  language

middle level  language

high level  language



Question 2

What is the  error in the program?

char count;

main()

{

int count =  70;

{

extern int  count;

printf("\n  %d ", count);

}

}



Error: Type  mismatch in redeclaration of ' nn'

Error:  Multiple declaration for 'nn'

Error: Storage  class 'extern' is not allowed here

Linker Error:  Undefined symbol 'nn'





Question 3

What is the  output of the program?



void main()

{

int val = (5,  val = 5)/++val;

printf("\n  %d ", val);

}



5

1

6

0





Question 4

Which of the  following statements is used to return more than one value from a function?



return 1,2,3 ;

return (1,2,3)  ;

return ((1),  (2), (3));

None of the  above





Question 5

Which of the  following is wrong with respect to structures?



Having the  same name for a structure and its variable

It has  functions as its data members

It has a data  member, which is of the same structure kind

Both B and C





Question 6

What is the  error in the code shown below?



union

{

int val1 : 5;

char val2;

};



Declaration of  variables is not possible due to the absence of tag name

Arrays of this  union cannot be created

Cannot be used  in file handling

All the three  B, C and D





Question 7

What is an  '&' operator?



logical

unary

bitwise

ternary





Question 8

What is the  difference between malloc and calloc?



in allocation  of memory

in return  types

number of  arguments

None of the  above





Question 9

What is the  default promotion for 'float' in va_arg?



double

int

long int

char





Question 10

What is the  error in the program?



main()

{

int a = 12;

int *ptr =  &a;

printf( "  %d %d ", *ptr /*ptr, *ptr**ptr);

}



No error,  output is 1 144



No error,  output is 144 144



Unexpected end  of file found



Error: illegal  pointer operation





Question 11

What is the  significance of the function realloc()?



realloc()  adjusts the size of the allocated block to specified size

realloc()  allocates memory on far heap

It is used to  allocate more than 64k bytes

realloc()  allocates the specified number of bytes in registers





Question 12

What is the  error in the program?



main()

{

typedef struct  personal

{

int  name[25]:15;

}

personal;  personal person;

}



Error: Bit  fields must be signed or unsigned int

Error:  Multiple declaration for 'personal'

Error:  Undefined symbol 'personal'

Error: Size of  the type is unknown or zero





Question 13

What is the  return type of fflush()?



void

FILE*

char*

int





Question 14

What is the  error in the program?



void  myprintf()

{

printf("\n  %d ", printf("Genesis"));

}

main() {

printf("\n  %d ", myprintf());

}



Error: Type  mismatch in 'printf'

The return  type of a function must be an integer

Error: printf  cannot return anything

Cannot convert  from 'void' to '...'





Question 15

What is the  meaning of a static function?



It is local to  a file in which it is declared

It is local to  main()

The set of  variables used in the function is 'static'

All the linked  files can access it





Question 16

What is the  output of the program?



# include  <stdio.h>



void main()

{

int main = 90;

top :  printf("Label1");

if(main)

goto top;

}



Infinite

Label1

No output

label top is  invalid





Question 17

How many times  is the 'for' loop/statement is executed in the following code.



main()

{

unsigned char  ch;

for(ch = 0; ch  <= 255; ch++);

}



Infinite

255

256

127





Question 18

What is  maximum number of 'case' values in a switch statement?



255

127

No specific  limit

128





Question 19

What is the  output of the program?



void main()

{

int x = (90, x  = 90)+++x;

printf("\n  %d ", x);

}



90

1

181

91





Question 20

Where do we  use a 'continue' statement?



In 'if'  statement

In 'switch'  statement

In 'goto'  labels

None of the  above





Answers

Answer 1 - C

Answer 2 - A

Answer 3 - B

Answer 4 - D

Answer 5 - D

Answer 6 - D

Answer 7 - C

Answer 8 - C

Answer 9 - A

Answer 10 - C

Answer 11 - A

Answer 12 - A

Answer 13 - D

Answer 14 - D

Answer 15 - A

Answer 16 - A

Answer 17 - A

Answer 18 - C

Answer 19 - C

Answer 20 - D

C Question Set 1-7


Question 1

'C' is a

machine  language

low level  language

middle level  language

high level  language



Question 2

What is the  error in the program?

char count;

main()

{

int count =  70;

{

extern int  count;

printf("\n  %d ", count);

}

}



Error: Type  mismatch in redeclaration of ' nn'

Error:  Multiple declaration for 'nn'

Error: Storage  class 'extern' is not allowed here

Linker Error:  Undefined symbol 'nn'





Question 3

What is the  output of the program?



void main()

{

int val = (5,  val = 5)/++val;

printf("\n  %d ", val);

}



5

1

6

0





Question 4

Which of the  following statements is used to return more than one value from a function?



return 1,2,3 ;

return (1,2,3)  ;

return ((1),  (2), (3));

None of the  above





Question 5

Which of the  following is wrong with respect to structures?



Having the  same name for a structure and its variable

It has  functions as its data members

It has a data  member, which is of the same structure kind

Both B and C





Question 6

What is the  error in the code shown below?



union

{

int val1 : 5;

char val2;

};



Declaration of  variables is not possible due to the absence of tag name

Arrays of this  union cannot be created

Cannot be used  in file handling

All the three  B, C and D





Question 7

What is an  '&' operator?



logical

unary

bitwise

ternary





Question 8

What is the  difference between malloc and calloc?



in allocation  of memory

in return  types

number of  arguments

None of the  above





Question 9

What is the  default promotion for 'float' in va_arg?



double

int

long int

char





Question 10

What is the  error in the program?



main()

{

int a = 12;

int *ptr =  &a;

printf( "  %d %d ", *ptr /*ptr, *ptr**ptr);

}



No error,  output is 1 144



No error,  output is 144 144



Unexpected end  of file found



Error: illegal  pointer operation





Question 11

What is the  significance of the function realloc()?



realloc()  adjusts the size of the allocated block to specified size

realloc()  allocates memory on far heap

It is used to  allocate more than 64k bytes

realloc()  allocates the specified number of bytes in registers





Question 12

What is the  error in the program?



main()

{

typedef struct  personal

{

int  name[25]:15;

}

personal;  personal person;

}



Error: Bit  fields must be signed or unsigned int

Error:  Multiple declaration for 'personal'

Error:  Undefined symbol 'personal'

Error: Size of  the type is unknown or zero





Question 13

What is the  return type of fflush()?



void

FILE*

char*

int





Question 14

What is the  error in the program?



void  myprintf()

{

printf("\n  %d ", printf("Genesis"));

}

main() {

printf("\n  %d ", myprintf());

}



Error: Type  mismatch in 'printf'

The return  type of a function must be an integer

Error: printf  cannot return anything

Cannot convert  from 'void' to '...'





Question 15

What is the  meaning of a static function?



It is local to  a file in which it is declared

It is local to  main()

The set of  variables used in the function is 'static'

All the linked  files can access it





Question 16

What is the  output of the program?



# include  <stdio.h>



void main()

{

int main = 90;

top :  printf("Label1");

if(main)

goto top;

}



Infinite

Label1

No output

label top is  invalid





Question 17

How many times  is the 'for' loop/statement is executed in the following code.



main()

{

unsigned char  ch;

for(ch = 0; ch  <= 255; ch++);

}



Infinite

255

256

127





Question 18

What is  maximum number of 'case' values in a switch statement?



255

127

No specific  limit

128





Question 19

What is the  output of the program?



void main()

{

int x = (90, x  = 90)+++x;

printf("\n  %d ", x);

}



90

1

181

91





Question 20

Where do we  use a 'continue' statement?



In 'if'  statement

In 'switch'  statement

In 'goto'  labels

None of the  above





Answers

Answer 1 - C

Answer 2 - A

Answer 3 - B

Answer 4 - D

Answer 5 - D

Answer 6 - D

Answer 7 - C

Answer 8 - C

Answer 9 - A

Answer 10 - C

Answer 11 - A

Answer 12 - A

Answer 13 - D

Answer 14 - D

Answer 15 - A

Answer 16 - A

Answer 17 - A

Answer 18 - C

Answer 19 - C

Answer 20 - D

C Question Set 1-6


Question 1
What is the output of the program?

#include <stdio.h>
// Assume size of integer as 4 bytes
void main()
{
char (*p)[3];
printf("\n %d %d", sizeof(*p), sizeof(p));
}

12 4
3 4
1 3
4 12


Question 2
What is the output of the program?

#include <stdio.h>

void main()
{
const char* ptr = "Genesis";
printf(" %c ", (*++ptr)++);
}

No error, output is e
No error, output is n
No error, output is G
l-value specifies const object


Question 3
The functionality of "ferror(FILE *)" is

ferror is a macro that tests the given stream for a read error only
ferror is a macro that tests the given stream for a file open error
ferror is a macro that tests the given stream for a read or write error
ferror is a macro that tests the given stream for a file close error


Question 4
Which of the following function does not return an integer value?

printf
scanf
strcpy
strlen


Question 5
What is the output of the program?

#include <stdio.h>
main()
{
static char Arr[8] = "Genesis";
char* ptr = &Arr[6] - 3;
printf("\n %s", ptr);
}

e
sis
esis
n


Question 6
Which of the following functions support dynamic memory allocation?

malloc
realloc
calloc
All the three A, B and C


Question 7
What is the significance of putw() function?

writes only character data to the file in text mode
writes only integer data to the file in binary mode
writes integer data to the file in text mode
writes character data to the file in binary mode


Question 8
What is the output of the program?

#include <stdio.h>
main()
{
for( ; ; )
main();
}

Error: syntax error at or before;
Executes once
It will result in infinite loop until stack overflow occurs
Error: illegal call to function main()


Question 9
What is the output of the program?

#include <stdio.h>

// Assume integer is 4 bytes
struct {
char *p;
int (*fun)();
} a;

void main()
{
printf("\n %d %d %d ", sizeof(a), sizeof(a.p), sizeof(a.fun));
}

8 4 4
5 1 4
6 2 4
Error: pointer to functions is not allowed in structures


Question 10
What is the output of the program?

#include <stdio.h>

void main()
{
int Var = 90;
if(Var += Var == ++Var == 89)
printf(" %d ",Var);
}

180
91
90
182


Question 11
Which of the functions always write the output to Video Display Unit?

puts
putc
putch
fputs


Question 12
Which of the declarations cannot be performed above main()?

variables of auto storage class
enum declaration
variables of extern storage class
static union declaration


Question 13
What is the output of the program if the input is 103?

main()
{
int p = 234;
printf(" %d ", printf("%d", p), scanf("%d", &p));
}

3 103
103
103 3
103 2


Question 14
What is the difference between scanf() and gets() while scanning a bunch of characters??

scanf() takes input from stdin, but gets() gets input from console
scanf() put a null at the end of the string, but gets() does not
gets() can scan even the spaces, but scanf() cannot
None of the above


Question 15
Which of the functions compares two strings ignoring the case?

strcmp
strncmp
stricmp
strcpy


Question 16
What is the output of the program?

int fun(int num)
{
return printf(" %d ", num);
}

void main()
{
printf(" Genesis ", fun(123), " & Genesis");
}

123 Genesis
Genesis 123
3 Genesis
None of the above


Question 17
What is the output of the program?

void print(char *s)
{
if(*s)
print(++s);
printf("%c", *s);
}

main()
{
char str[] = "Genesis";
print(str);
}

genesis
sisene
siseneg
None of the above


Question 18
Where will the output of the program be printed?

main()
{
fprintf(stdprn, "Genesis InSoft Limited") ;
}

Standard output device
Standard error output device
Standard auxiliary device
Standard printer


Question 19
What is the output of the program?

const int MAX = 15;
void main()
{
enum e{a, b, MAX};
printf("%d %d %d", a, b, MAX);
}

0 1 2
1 2 3
1 2 15
0 1 15


Question 20
What is the purpose of the fcloseall() function?
closes all the streams including standard streams
closes all the streams other than standard streams
closes all the input streams
closes all the output streams

Answers
Answer 1 - B
Answer 2 - D
Answer 3 - C
Answer 4 - C
Answer 5 - C
Answer 6 - D
Answer 7 - B
Answer 8 - C
Answer 9 - A
Answer 10 - B
Answer 11 - C
Answer 12 - A
Answer 13 - C
Answer 14 - D
Answer 15 - C
Answer 16 - A
Answer 17 - B
Answer 18 - D
Answer 19 - A
Answer 20 - B

C Question Set 1-6


Question 1
What is the output of the program?

#include <stdio.h>
// Assume size of integer as 4 bytes
void main()
{
char (*p)[3];
printf("\n %d %d", sizeof(*p), sizeof(p));
}

12 4
3 4
1 3
4 12


Question 2
What is the output of the program?

#include <stdio.h>

void main()
{
const char* ptr = "Genesis";
printf(" %c ", (*++ptr)++);
}

No error, output is e
No error, output is n
No error, output is G
l-value specifies const object


Question 3
The functionality of "ferror(FILE *)" is

ferror is a macro that tests the given stream for a read error only
ferror is a macro that tests the given stream for a file open error
ferror is a macro that tests the given stream for a read or write error
ferror is a macro that tests the given stream for a file close error


Question 4
Which of the following function does not return an integer value?

printf
scanf
strcpy
strlen


Question 5
What is the output of the program?

#include <stdio.h>
main()
{
static char Arr[8] = "Genesis";
char* ptr = &Arr[6] - 3;
printf("\n %s", ptr);
}

e
sis
esis
n


Question 6
Which of the following functions support dynamic memory allocation?

malloc
realloc
calloc
All the three A, B and C


Question 7
What is the significance of putw() function?

writes only character data to the file in text mode
writes only integer data to the file in binary mode
writes integer data to the file in text mode
writes character data to the file in binary mode


Question 8
What is the output of the program?

#include <stdio.h>
main()
{
for( ; ; )
main();
}

Error: syntax error at or before;
Executes once
It will result in infinite loop until stack overflow occurs
Error: illegal call to function main()


Question 9
What is the output of the program?

#include <stdio.h>

// Assume integer is 4 bytes
struct {
char *p;
int (*fun)();
} a;

void main()
{
printf("\n %d %d %d ", sizeof(a), sizeof(a.p), sizeof(a.fun));
}

8 4 4
5 1 4
6 2 4
Error: pointer to functions is not allowed in structures


Question 10
What is the output of the program?

#include <stdio.h>

void main()
{
int Var = 90;
if(Var += Var == ++Var == 89)
printf(" %d ",Var);
}

180
91
90
182


Question 11
Which of the functions always write the output to Video Display Unit?

puts
putc
putch
fputs


Question 12
Which of the declarations cannot be performed above main()?

variables of auto storage class
enum declaration
variables of extern storage class
static union declaration


Question 13
What is the output of the program if the input is 103?

main()
{
int p = 234;
printf(" %d ", printf("%d", p), scanf("%d", &p));
}

3 103
103
103 3
103 2


Question 14
What is the difference between scanf() and gets() while scanning a bunch of characters??

scanf() takes input from stdin, but gets() gets input from console
scanf() put a null at the end of the string, but gets() does not
gets() can scan even the spaces, but scanf() cannot
None of the above


Question 15
Which of the functions compares two strings ignoring the case?

strcmp
strncmp
stricmp
strcpy


Question 16
What is the output of the program?

int fun(int num)
{
return printf(" %d ", num);
}

void main()
{
printf(" Genesis ", fun(123), " & Genesis");
}

123 Genesis
Genesis 123
3 Genesis
None of the above


Question 17
What is the output of the program?

void print(char *s)
{
if(*s)
print(++s);
printf("%c", *s);
}

main()
{
char str[] = "Genesis";
print(str);
}

genesis
sisene
siseneg
None of the above


Question 18
Where will the output of the program be printed?

main()
{
fprintf(stdprn, "Genesis InSoft Limited") ;
}

Standard output device
Standard error output device
Standard auxiliary device
Standard printer


Question 19
What is the output of the program?

const int MAX = 15;
void main()
{
enum e{a, b, MAX};
printf("%d %d %d", a, b, MAX);
}

0 1 2
1 2 3
1 2 15
0 1 15


Question 20
What is the purpose of the fcloseall() function?
closes all the streams including standard streams
closes all the streams other than standard streams
closes all the input streams
closes all the output streams

Answers
Answer 1 - B
Answer 2 - D
Answer 3 - C
Answer 4 - C
Answer 5 - C
Answer 6 - D
Answer 7 - B
Answer 8 - C
Answer 9 - A
Answer 10 - B
Answer 11 - C
Answer 12 - A
Answer 13 - C
Answer 14 - D
Answer 15 - C
Answer 16 - A
Answer 17 - B
Answer 18 - D
Answer 19 - A
Answer 20 - B

C Question Set 1-4


Question1
Reusability of code in C is supported by

Functions
Macros
Pointers
Files

Question 2
The entry point of the 'C' program is with

#include
main(int argc, char * argv)
c_main
MAIN()

Question 3
When a const variable is declared, it is stored

in RAM
in ROM
on heap
in CPU registers

Question 4
What is the output of the program?
#include <stdio.h>
int main(int argc, char *argv[])
{
printf(" %d", printf("Hello Genesis"));
return 0;
}

Hello Genesis
13 Hello Genesis
Hello Genesis 13
None of the above

Question 5
What is the output of the program?
#include <stdio.h>

void main()
{
printf("\n Hi" " %s ", "Genesis"" InSoft");
}

Hi %s Genesis InSoft
Hi Genesis
Hi Genesis InSoft
Hi %s Genesis InSoft
Question 6
What is the output of the program?
#include <stdio.h>
main()
{
switch (5)
{
case 5: printf(" 5 ");
default: printf(" 10 ");
case 6: printf(" 6 ");
}
}
5
5 10
5 10 6
5 6

Question 7
What is the output of the program?

#include <stdio.h>

void main()
{
int x = 9;
Continue: printf("\n Continue ");
if(!x)
goto gen;
gen: printf(" Genesis ");
}

Genesis
Continue Genesis
Continue
None of the above


Question 8
Which argument of function 'strncmp()' specifies number of characters to be compared?

first
second
third
fourth

Question 9
Which of the following is not a storage class in C?

Static
Register
Extern
Stack


Question 10
Which of the following 'return' statement is correct?

return, return;
return(1, 2, 3);
return(return 4);
(return 5, return 6);


Question 11
The second argument to fopen() function is?

char
const char *
int *
FILE *


Question 12
What is the data type of FILE?

integer
union
pointer
structure


Question 13
The first argument of fwrite function is typecast to

char *
FILE *
int *
void *


Question 14
Which of the following storage class variables cannot be used with pointers?

extern
static
register
Both A and C


Question 15
What is the output of the program?

#include <stdio.h>

void main()
{
int (*myprintf)(const char*, ...) = printf;
myprintf("Genesis InSoft Limited");
}

Genesis InSoft Limited
No output
Undefined symbol myprintf
Prototype mismatch

Question 16
What is the output of the program?

#include <stdio.h>

void main()
{
char buffer[10] = {"Genesis"};
printf(" %d ", &buffer[4]- (buffer));
}

3
4
0
Illegal pointer subtraction

Question 17
If "arr" is an array of 5 x 5 dimension, arr[2][4] is same as

**(a+3+4)
*(a+3)+*(a+4)
**(a+3)+4
*(*(a+2)+4)


Question 18
What is the significance of the free() function?

It erases the contents of any type and cleans the pointer
It places the memory address with the pointer in free store
It assigns the pointer a NULL value
It disables the memory address with the pointer


Question 19
The following statement is used in C for

char *ptr = (char*) malloc(Length);

For faster execution of programs
For reducing the code
For conservation of memory
Both A and B

Question 20
What is the output of the program?

#include <stdio.h>
#define sq(a) a * a

void main()
{
printf("%d", sq(3 + 2));
}

25
11
10
Compilation error


Answers
Answer 1 - A
Answer 2 - B
Answer 3 - B
Answer 4 - C
Answer 5 - C
Answer 6 - C
Answer 7 - B
Answer 8 - C
Answer 9 - D
Answer 10 - B
Answer 11 - B
Answer 12 - D
Answer 13 - D
Answer 14 - C
Answer 15 - A
Answer 16 - B
Answer 17 - D
Answer 18 - B
Answer 19 - C
Answer 20 - B

C Question Set 1-5


Question 1

The number of  components in a doubly linked list is



1

2

3

4



Question 2

What is the  output of the program?



#include  <stdio.h>

void main()

{

unsigned short  a = -4; // Assume short is 2 bytes

printf("\n  %u", a);

}



Error:  Variable of type unsigned char cannot store negative values

4

-4

65532





Question 3

Which of the  following is a non-linear data structure?



Stack

Queue

Linked List

Tree





Question 4

Function time  (time_t*) is used to get the



current system  time

time taken for  the program to execute

file updation  time

file creation  time





Question 5

Macros



Expands the  code size

Perform dumb  substitution

Reduce the  speed of program execution

Both A and B





Question 6

Which of the  options helps the programmer in debugging a program?



Watch

Building a  project

Conditional  compilation

Both A and C





Question 7

How can you  correct improper naming of function?



By type  defining the function

By declaring  pointer to functions

By # defining  the name

By redefining  the function





Question 8

Memory  conservation is possible using



Unions

Static  variables

Arrays

Bit fields





Question 9

What is the  output of the program?



#include  <stdio.h>

#define MAX 20

void main()

{

printf("%d",  ++MAX));

}



No error,  output is 20

No error,  output is 21

Error: Define  directive needs an identifier

Error: Lvalue  required





Question 10

What is the  output of the program?



#include  <stdio.h>

#define SQ(a)  a*a



void main()

{

printf("%d",  SQ(2+3));

}



11

25

Error in  compilation

13





Question 11

'C' language  was developed to achieve



Portability

Modularity

Platform  independence

Reusability





Question 12

How many bytes  are allocated for "int" declaration?



minimum 2

only 2

minimum 4

only 4





Question 13

Which of the  following data types has the same size irrespective of the operating system?



char*

int

float

char





Question 14

What is the  output of the program?



#include  <stdio.h>

void main()

{

int m = (m =  1, m++, --m);

printf("\n  %d ", m);

}



Error:  undefined symbol 'm'

2

1

3





Question 15

What is the  output of the program?



#include  <stdio.h>

void main()

{

printf("%d",  sizeof(int) ? 1 ? 2 : 3 ? 4 : 5);

}



Error: Lvalue  required

syntax error:  missing : before )

2

3





Question 16

A switch  statement is similar to



while

do - while

multiple if -  else if - else

for





Question 17

Which of the  following function returns an integer data type?



strncpy

strcmp

strstr

strcat





Question 18

Which of the  following statements is correct?



when a pointer  is incremented by 1 the address contained in the pointer is incremented by 1

when a pointer  is incremented by 1 the address contained in the pointer is incremented by size  of integer

when a pointer  is incremented by 1 the address contained in the pointer is incremented  according to the type of pointer

when a pointer  is incremented by 1 the address contained in the pointer is incremented  according to the type it is pointing to





Question 19

What is the  output of the program?



#include  <stdio.h>

void main()

{

static int a[]  = {5, 10, 15, 20};

int* ptr = a;

int** ptr_ptr  = &ptr;

printf("\n  %d",**ptr_ptr++);

}



5

10

15

20





Question 20

The compiler  evaluates the operator '*' as either a pointer indirection or multiplication  based on



the operator  precedence

the number of  operands

the type of  operands

its location  in the source code





Answers

Answer 1 - C

Answer 2 - D

Answer 3 - D

Answer 4 - A

Answer 5 - D

Answer 6 - D

Answer 7 - B

Answer 8 - D

Answer 9 - D

Answer 10 - A

Answer 11 - A

Answer 12 - A

Answer 13 - D

Answer 14 - C

Answer 15 - B

Answer 16 - C

Answer 17 - B

Answer 18 - C

Answer 19 - A

Answer 20 - B

C Question Set 1-4


Question1
Reusability of code in C is supported by

Functions
Macros
Pointers
Files

Question 2
The entry point of the 'C' program is with

#include
main(int argc, char * argv)
c_main
MAIN()

Question 3
When a const variable is declared, it is stored

in RAM
in ROM
on heap
in CPU registers

Question 4
What is the output of the program?
#include <stdio.h>
int main(int argc, char *argv[])
{
printf(" %d", printf("Hello Genesis"));
return 0;
}

Hello Genesis
13 Hello Genesis
Hello Genesis 13
None of the above

Question 5
What is the output of the program?
#include <stdio.h>

void main()
{
printf("\n Hi" " %s ", "Genesis"" InSoft");
}

Hi %s Genesis InSoft
Hi Genesis
Hi Genesis InSoft
Hi %s Genesis InSoft
Question 6
What is the output of the program?
#include <stdio.h>
main()
{
switch (5)
{
case 5: printf(" 5 ");
default: printf(" 10 ");
case 6: printf(" 6 ");
}
}
5
5 10
5 10 6
5 6

Question 7
What is the output of the program?

#include <stdio.h>

void main()
{
int x = 9;
Continue: printf("\n Continue ");
if(!x)
goto gen;
gen: printf(" Genesis ");
}

Genesis
Continue Genesis
Continue
None of the above


Question 8
Which argument of function 'strncmp()' specifies number of characters to be compared?

first
second
third
fourth

Question 9
Which of the following is not a storage class in C?

Static
Register
Extern
Stack


Question 10
Which of the following 'return' statement is correct?

return, return;
return(1, 2, 3);
return(return 4);
(return 5, return 6);


Question 11
The second argument to fopen() function is?

char
const char *
int *
FILE *


Question 12
What is the data type of FILE?

integer
union
pointer
structure


Question 13
The first argument of fwrite function is typecast to

char *
FILE *
int *
void *


Question 14
Which of the following storage class variables cannot be used with pointers?

extern
static
register
Both A and C


Question 15
What is the output of the program?

#include <stdio.h>

void main()
{
int (*myprintf)(const char*, ...) = printf;
myprintf("Genesis InSoft Limited");
}

Genesis InSoft Limited
No output
Undefined symbol myprintf
Prototype mismatch

Question 16
What is the output of the program?

#include <stdio.h>

void main()
{
char buffer[10] = {"Genesis"};
printf(" %d ", &buffer[4]- (buffer));
}

3
4
0
Illegal pointer subtraction

Question 17
If "arr" is an array of 5 x 5 dimension, arr[2][4] is same as

**(a+3+4)
*(a+3)+*(a+4)
**(a+3)+4
*(*(a+2)+4)


Question 18
What is the significance of the free() function?

It erases the contents of any type and cleans the pointer
It places the memory address with the pointer in free store
It assigns the pointer a NULL value
It disables the memory address with the pointer


Question 19
The following statement is used in C for

char *ptr = (char*) malloc(Length);

For faster execution of programs
For reducing the code
For conservation of memory
Both A and B

Question 20
What is the output of the program?

#include <stdio.h>
#define sq(a) a * a

void main()
{
printf("%d", sq(3 + 2));
}

25
11
10
Compilation error


Answers
Answer 1 - A
Answer 2 - B
Answer 3 - B
Answer 4 - C
Answer 5 - C
Answer 6 - C
Answer 7 - B
Answer 8 - C
Answer 9 - D
Answer 10 - B
Answer 11 - B
Answer 12 - D
Answer 13 - D
Answer 14 - C
Answer 15 - A
Answer 16 - B
Answer 17 - D
Answer 18 - B
Answer 19 - C
Answer 20 - B

C Question Set 1-5


Question 1

The number of  components in a doubly linked list is



1

2

3

4



Question 2

What is the  output of the program?



#include  <stdio.h>

void main()

{

unsigned short  a = -4; // Assume short is 2 bytes

printf("\n  %u", a);

}



Error:  Variable of type unsigned char cannot store negative values

4

-4

65532





Question 3

Which of the  following is a non-linear data structure?



Stack

Queue

Linked List

Tree





Question 4

Function time  (time_t*) is used to get the



current system  time

time taken for  the program to execute

file updation  time

file creation  time





Question 5

Macros



Expands the  code size

Perform dumb  substitution

Reduce the  speed of program execution

Both A and B





Question 6

Which of the  options helps the programmer in debugging a program?



Watch

Building a  project

Conditional  compilation

Both A and C





Question 7

How can you  correct improper naming of function?



By type  defining the function

By declaring  pointer to functions

By # defining  the name

By redefining  the function





Question 8

Memory  conservation is possible using



Unions

Static  variables

Arrays

Bit fields





Question 9

What is the  output of the program?



#include  <stdio.h>

#define MAX 20

void main()

{

printf("%d",  ++MAX));

}



No error,  output is 20

No error,  output is 21

Error: Define  directive needs an identifier

Error: Lvalue  required





Question 10

What is the  output of the program?



#include  <stdio.h>

#define SQ(a)  a*a



void main()

{

printf("%d",  SQ(2+3));

}



11

25

Error in  compilation

13





Question 11

'C' language  was developed to achieve



Portability

Modularity

Platform  independence

Reusability





Question 12

How many bytes  are allocated for "int" declaration?



minimum 2

only 2

minimum 4

only 4





Question 13

Which of the  following data types has the same size irrespective of the operating system?



char*

int

float

char





Question 14

What is the  output of the program?



#include  <stdio.h>

void main()

{

int m = (m =  1, m++, --m);

printf("\n  %d ", m);

}



Error:  undefined symbol 'm'

2

1

3





Question 15

What is the  output of the program?



#include  <stdio.h>

void main()

{

printf("%d",  sizeof(int) ? 1 ? 2 : 3 ? 4 : 5);

}



Error: Lvalue  required

syntax error:  missing : before )

2

3





Question 16

A switch  statement is similar to



while

do - while

multiple if -  else if - else

for





Question 17

Which of the  following function returns an integer data type?



strncpy

strcmp

strstr

strcat





Question 18

Which of the  following statements is correct?



when a pointer  is incremented by 1 the address contained in the pointer is incremented by 1

when a pointer  is incremented by 1 the address contained in the pointer is incremented by size  of integer

when a pointer  is incremented by 1 the address contained in the pointer is incremented  according to the type of pointer

when a pointer  is incremented by 1 the address contained in the pointer is incremented  according to the type it is pointing to





Question 19

What is the  output of the program?



#include  <stdio.h>

void main()

{

static int a[]  = {5, 10, 15, 20};

int* ptr = a;

int** ptr_ptr  = &ptr;

printf("\n  %d",**ptr_ptr++);

}



5

10

15

20





Question 20

The compiler  evaluates the operator '*' as either a pointer indirection or multiplication  based on



the operator  precedence

the number of  operands

the type of  operands

its location  in the source code





Answers

Answer 1 - C

Answer 2 - D

Answer 3 - D

Answer 4 - A

Answer 5 - D

Answer 6 - D

Answer 7 - B

Answer 8 - D

Answer 9 - D

Answer 10 - A

Answer 11 - A

Answer 12 - A

Answer 13 - D

Answer 14 - C

Answer 15 - B

Answer 16 - C

Answer 17 - B

Answer 18 - C

Answer 19 - A

Answer 20 - B

C Question Set 1-3


Question 1

What  restrictions apply to reference variables?



You cannot  reference a reference variable (i.e. you cannot take its address)

You cannot  create arrays of references

References are  not allowed on bit fields

All of the  above



Question 2

What is the  output of the program?



#include  <iostream.h>

struct Emp

{

int id;

float basic;

float  cal_salary();

void  show_emp();

};

void main()

{

Emp e1;

e1.basic =  5000.5;

cout <<  e1.basic <<endl;

}



5000

5000.5

Error - as  private data cannot be accessed

None of the  above



Question 3

What is the  output of the program?



#include  <iostream.h>

class test

{

test()

{

cout <<  "constructor called" ;

}

};



void main()

{

test a();

}



constructor  called

Error -  constructor cannot be private

no output is  displayed

None of the  above





Question 4

What is the  output of the program?

#include  <iostream.h>

class test

{

int x;

public:

test(int y)

{

x = y;

}



int getX()

{

int x = 40;

return  this->x;

}

};



void main()

{

test a(10);

cout <<  a.getX();

}

Compilation  error

10

40

None of the  above



Question 5

What is the  prototype of pre increment operator in class test?



void operator  ++ ();

test operator  ++ (int);

void operator  ++ (int);

test operator  ++ ();



Question 6

What  restrictions apply to extern "C"?



You can  specify extern "C" for only one instance of an overloaded function;  all other instances of an overloaded function have C++ linkage

You can only  declare C functions as 'extern "C"

You cannot  declare a member function with extern "C"

Both A and C



Question 7

What is the  output of the program?



#include  <iostream.h>



void fun(int  & a, int b)

{

a += 20;

b += 30;

}



void main()

{

int x = 10, y  = 50;

fun(x, y);

cout <<  x << " " << y ;

}



30 80

10 50

30 50

10 80



Question 8

What is the  output of the following?

#include  <iostream.h>

class test

{

char x;

static char c;

};

void main()

{

test a;

cout <<  sizeof(a);

}



1

2

4

None of the  above

Question 9

What is the  signature of the output operator for class test?

friend ostream  & operator << (test &);

ostream &  operator << (test &);

ostream &  operator << (ostream &, test &);

friend ostream  & operator << (ostream &, test &);



Question 10

What is the  member function called in the statement "test b = a" shown below?

void main()

{

test a(10);

test b = a;

}



Assignment  operator

Constructor

Copy  constructor

None of the  above



Question 11

A variable  that is part of a class, yet is not part of an object of that class, is called  a?



Static member

Friend member

Constant  member

Non-static  member



Question 12

The only  member functions that could be called for const objects would be?

Constructors

Destructor

Const member  functions

All of the  above



Question 13

Which of the  following type conversions is automatic?



Conversion  from built-in type to class type

Conversion  from class type to built-in type

Conversion  from one class type to another class type

None of the  above



Question 14

Which keyword  do we use if the data members of the class are to be modified even when it  belongs to a constant object?



mutable

static

const

friend



Question 15

Which  condition should the conversion function from class type to built-in type  satisfy?



It must be a  class member

It must not  specify a return type

It must not  have any arguments

All of the  above

Question 16

We prefer  initialization to assignment for the following reason?



Const members  can only be initialized

Reference  members can only be initialized

To improve the  efficiency, when a class contains a data member which is an object of another  class

All of the  above

Question 17

Which keyword  specifies that those members are accessible only from member functions and  friends of the class and its derived classes?



private

public

protected

All of the  above



Question 18

Which of the  following statements is correct?



When preceding  the name of a base class, the protected keyword specifies that the public and  protected members of the base class are protected members of the derived class

Default access  of a base class is private for classes

Default access  of a base class is public for structures

All of the  above



Question 19

What is the  output of the program?

# include  <iostream.h>

union test {

int x;

};

class uc :  public test

{

int y;

};

main()

{

uc u;

cout <<  sizeof(u);

}

8

4

union cannot  be used as base class

None of the  above



Question 20

Which of the  following statements are true about static member functions?

Cannot make  use of this pointer

Cannot access  any non-static data

Cannot be  declared const

All of the  above



Answers

Answer 1 - D

Answer 2 - B

Answer 3 - C

Answer 4 - B

Answer 5 - D

Answer 6 - D

Answer 7 - C

Answer 8 - A

Answer 9 - D

Answer 10 - C

Answer 11 - A

Answer 12 - D

Answer 13 - D

Answer 14 - A

Answer 15 - D

Answer 16 - D

Answer 17 - C

Answer 18 - D

Answer 19 - C

Answer 20 - D

C Question Set 1-3


Question 1

What  restrictions apply to reference variables?



You cannot  reference a reference variable (i.e. you cannot take its address)

You cannot  create arrays of references

References are  not allowed on bit fields

All of the  above



Question 2

What is the  output of the program?



#include  <iostream.h>

struct Emp

{

int id;

float basic;

float  cal_salary();

void  show_emp();

};

void main()

{

Emp e1;

e1.basic =  5000.5;

cout <<  e1.basic <<endl;

}



5000

5000.5

Error - as  private data cannot be accessed

None of the  above



Question 3

What is the  output of the program?



#include  <iostream.h>

class test

{

test()

{

cout <<  "constructor called" ;

}

};



void main()

{

test a();

}



constructor  called

Error -  constructor cannot be private

no output is  displayed

None of the  above





Question 4

What is the  output of the program?

#include  <iostream.h>

class test

{

int x;

public:

test(int y)

{

x = y;

}



int getX()

{

int x = 40;

return  this->x;

}

};



void main()

{

test a(10);

cout <<  a.getX();

}

Compilation  error

10

40

None of the  above



Question 5

What is the  prototype of pre increment operator in class test?



void operator  ++ ();

test operator  ++ (int);

void operator  ++ (int);

test operator  ++ ();



Question 6

What  restrictions apply to extern "C"?



You can  specify extern "C" for only one instance of an overloaded function;  all other instances of an overloaded function have C++ linkage

You can only  declare C functions as 'extern "C"

You cannot  declare a member function with extern "C"

Both A and C



Question 7

What is the  output of the program?



#include  <iostream.h>



void fun(int  & a, int b)

{

a += 20;

b += 30;

}



void main()

{

int x = 10, y  = 50;

fun(x, y);

cout <<  x << " " << y ;

}



30 80

10 50

30 50

10 80



Question 8

What is the  output of the following?

#include  <iostream.h>

class test

{

char x;

static char c;

};

void main()

{

test a;

cout <<  sizeof(a);

}



1

2

4

None of the  above

Question 9

What is the  signature of the output operator for class test?

friend ostream  & operator << (test &);

ostream &  operator << (test &);

ostream &  operator << (ostream &, test &);

friend ostream  & operator << (ostream &, test &);



Question 10

What is the  member function called in the statement "test b = a" shown below?

void main()

{

test a(10);

test b = a;

}



Assignment  operator

Constructor

Copy  constructor

None of the  above



Question 11

A variable  that is part of a class, yet is not part of an object of that class, is called  a?



Static member

Friend member

Constant  member

Non-static  member



Question 12

The only  member functions that could be called for const objects would be?

Constructors

Destructor

Const member  functions

All of the  above



Question 13

Which of the  following type conversions is automatic?



Conversion  from built-in type to class type

Conversion  from class type to built-in type

Conversion  from one class type to another class type

None of the  above



Question 14

Which keyword  do we use if the data members of the class are to be modified even when it  belongs to a constant object?



mutable

static

const

friend



Question 15

Which  condition should the conversion function from class type to built-in type  satisfy?



It must be a  class member

It must not  specify a return type

It must not  have any arguments

All of the  above

Question 16

We prefer  initialization to assignment for the following reason?



Const members  can only be initialized

Reference  members can only be initialized

To improve the  efficiency, when a class contains a data member which is an object of another  class

All of the  above

Question 17

Which keyword  specifies that those members are accessible only from member functions and  friends of the class and its derived classes?



private

public

protected

All of the  above



Question 18

Which of the  following statements is correct?



When preceding  the name of a base class, the protected keyword specifies that the public and  protected members of the base class are protected members of the derived class

Default access  of a base class is private for classes

Default access  of a base class is public for structures

All of the  above



Question 19

What is the  output of the program?

# include  <iostream.h>

union test {

int x;

};

class uc :  public test

{

int y;

};

main()

{

uc u;

cout <<  sizeof(u);

}

8

4

union cannot  be used as base class

None of the  above



Question 20

Which of the  following statements are true about static member functions?

Cannot make  use of this pointer

Cannot access  any non-static data

Cannot be  declared const

All of the  above



Answers

Answer 1 - D

Answer 2 - B

Answer 3 - C

Answer 4 - B

Answer 5 - D

Answer 6 - D

Answer 7 - C

Answer 8 - A

Answer 9 - D

Answer 10 - C

Answer 11 - A

Answer 12 - D

Answer 13 - D

Answer 14 - A

Answer 15 - D

Answer 16 - D

Answer 17 - C

Answer 18 - D

Answer 19 - C

Answer 20 - D

C Question Set 1-2


Question 1
What does an empty class contain?

Default constructor
Copy constructor
Address of operator
All of the above

Question 2
In protected derivation

Protected and public members of base class become protected
Private, protected and public members of base class become protected
Private, protected and public members of base class become private
Protected and public members of base class become private

Question 3
What is the output of the program?
#include <iostream.h>
void main()
{
int j = 20, k = 30;
int & m = j;
int * n = &j;
cout << j << " " << k << " " << m << " ++ " ;
m = k;
cout << j << " " << k << " " << m << " ++ ";
n = &k; // n now points to k
cout << j << " " << k << " " << m << " " << *n << endl;
}

20 30 20 ++ 20 30 30 ++ 30 30 30 30
20 30 20 ++ 30 30 30 ++ 20 30 30 30
20 30 20 ++ 20 30 30 ++ 20 30 30 30
20 30 20 ++ 30 30 30 ++ 30 30 30 30

Question 4
Class istream in iostream.h is defined as
Class istream : public ios
Class istream : public virtual ios
Class istream : public iostream
Class istream : public virtual iostream

Question 5
Interface contains

At least one pure virtual function
No pure virtual function
All pure virtual functions
None of the above

Question 6
What is the size of empty class?

0 bytes
2 bytes
1 byte
4 bytes

Question 7
The advantage of defining a pure virtual member function in a class is

Derived class may implement the pure virtual function
Derived class must implement the pure virtual function
Derive class is abstract class if it does not implement the pure virtual function
Both B and C

Question 8
What is the output of the following?

#include
void main()
{
int x, y;
x=(3, 4, 5);
y=3, 4, 5;
cout << endl << x <<" "<< y;
}
Compilation Error
3 5
3 3
5 3

Question 9
What is the output of the following?
#include <iostream.h>
void main ()
{
{
for(int x=1; x <= 5; x++, x+=5);
}
cout << endl << " value of x = " << x;
}

6
7
compilation error
2

Question 10
What is the output of the following?
#include <iostream.h>
void main ()
{
cout << (cout<<" Hello ") << " world ";
}

No output is displayed
Hello some_address_value world
Hello world
compilation error

Question 11
The class fstreambuf serves as base class for

ifstream, ofstream, fstream
ifstream, ofstream
ostream
ifstream

Question 12
The scope resolution operator permits

Access to an identifier in the global scope that has been hidden by another identifier with the same name in the local scope
Access to an identifier in the global space
Access to an identifier in the local scope
Access to an identifier in the local scope and global scope

Question 13
The declaration
void func_name( )
accepts

Any no of arguments
Only one argument
No Arguments
None of the above

Question 14
The technique of allocating memory during runtime on demand is known as

Dynamic binding
Dynamic memory allocation
Late binding
Template

Question 15
What is the output of the following?
#include
void main()
{
enum col {red, blue, yellow};
col c = blue << 1;
cout << c;
}

1
2
3
4

Question 16
The advantage of defining a pure virtual member function in a class is

Derived class may implement the pure virtual function
Derived class must implement the pure virtual function
Derive class is abstract class if it does not implement the pure virtual function
Both B and C

Question 17
Input and output operators are known as

extraction and insertion
get from and put to
Both A and B
None of the above

Question 18
A file can be tied to your program by defining an instance of

fstream
ifstream
ofstream
All of the above

Question 19
Which of the following is not true about constructor

constructor can be overloaded
constructor return type is int
constructor has the same name as the class in which it is defined
constructor are used for initializing data members

Question 20
What is the output of the program?

#include <iostream.h>
char *buf1 = "Genesis", *buf2 = "InSoft";
void main()
{
const char *p = buf1;
p = buf2;
*p = 'g';
cout << *p;
}
What is the output of the program?
g
genesis
No ouput is displayed
l-value specifies constant object

Answers
Answer 1 - D
Answer 2 - A
Answer 3 - D
Answer 4 - B
Answer 5 - C
Answer 6 - C
Answer 7 - D
Answer 8 - D
Answer 9 - C
Answer 10 - B
Answer 11 - A
Answer 12 - A
Answer 13 - C
Answer 14 - C
Answer 15 - B
Answer 16 - D
Answer 17 - C
Answer 18 - D
Answer 19 - B
Answer 20 - D
======================================================================
C++ Question Bank 03 / FAQs [20 QUESTIONS]

Question 1
Which of the following statements is true?

A constant member function does allow changes to any data members in the class
A static member functions allows access to non-static data
The size of the object is the sum of size of all non-static data
The size of a struct variable is the sum of size of all static and all non-static data


Question 2
What is the output of the following?

#include
void main()
{
int x = 20;
int &t = x;
x = 50;
cout << x << " " << t;
}

20 50
50 20
50 50
None of the above

Question 3
Friend function adds flexibility to the language, but they are controversial

Because it goes against the rule of data encapsulation
Because it can access a class's private data
Both A and B
None of the above

Question 4
Which of the following is true about a destructor?

Destructor like a constructor can accept arguments
Destructor can be overloaded
Destructor function is the same name as a class which is preceded by the tilde character
Destructor return type is void


Question 5
The prototype of output operator in the class "test" is as follows

friend ostream & operator << (ostream &, test &)
ostream & operator << (ostream &, test &)
friend ostream & operator << (test &)
friend ostream & operator << (ostream &)

Question 6
Which of the following statements is false?

Friend functions take one argument more than a member function
Operator overloading allows us to create new operators
Static member functions can access only static data
A constant cannot be changed


Question 7
Which of the following statements is true?

We cannot overload operator new and operator delete
Each instance of a class has a different copy of static data
We need to define in every class a constructor and destructor
class istream extends class ios

Question 8
What is the output of the following?

#include <iostream.h>
int add(int, int = 5, int = 10);
void main() {
cout << add(10) << " " << add(10, 20) << " " << add(10, 20, 30);
}

int add(int a, int b, int c)
{
return a + b + c;
}

compilation error
25 40 60
15 30 60
20 40 60


Question 9
To turn overloading off, which of the statements is used?

extern "C"
static "C"
Register "C"
off "C"


Question 10
The keywords related to exception handling are?

test, catch
try, throw, catch
namespace, catch
try, finally


Question 11
Genericity is a technique to

Defining software components that have more than one interpretation depending on the data type of parameter.
Which allows the extension of the functionality of the existing software components.
To derive a class from more than one base class.
Of creating new data types that are well suited to an application.

Question 12
Comments are

Integral part of the program and they do nothing
Integral part of the program and they help in coding and maintenance
Are not part of the program
Are not part of the program and they slow down the execution speed

Question 13
C++ does not support the following feature?

Multiple inheritance
Polymorphism
Operator overloading
Automatic memory management

Question 14
What is the output of the program?

#include <iostream.h>
char *buf1 = "Genesis", *buf2 = "InSoft";
void main()
{
char* const q=buf1;
*q='x';
cout << *q;
}

x
xenesis
l-value specifies constant object
None of the above

Question 15
What happens when new operator is called?

It invokes operator new, then invokes the constructor and then does type casting
It invokes the constructor, calls operator new and then does type casting
It invokes operator new and then invokes the constructor
It invokes the constructor and then does type casting

Question 16
Which keyword violates data encapsulation?

Public
Virtual
Friend
Protected

Question 17
Which of the following is not true about destructor?

Destructor can be overloaded
A destructor class member function is typically used to return dynamically allocated memory
A destructor function has the same name as the class in which it is defined preceded by the tilde character
A destructor does not have any return type

Question 18
What is the output of the program?

#include <iostream.h>
void main()
{
int val = 5;
int &val1 = val;
int &val2;
cout << val1;
}

5
val2 - references must be initialized
Address of variable val is printed
None of the above

Question 19
What happens when delete operator is called?

It invokes operator delete and then invokes the destructor if any
It invokes the destructor if any and then calls operator delete
It invokes operator delete
It invokes the destructor if any

Question 20
Which of the following are true about default arguments?

Default arguments must be the last argument
A default argument cannot be redefined in later declarations even if the redefinition is identical to the original
Additional default arguments can be added by later declarations
All of the above

Answers
Answer 1 - C
Answer 2 - C
Answer 3 - C
Answer 4 - C
Answer 5 - A
Answer 6 - B
Answer 7 - D
Answer 8 - B
Answer 9 - A
Answer 10 - B
Answer 11 - A
Answer 12 - B
Answer 13 - D
Answer 14 - A
Answer 15 - A
Answer 16 - C
Answer 17 - A
Answer 18 - B
Answer 19 - A
Answer 20 - D

C Question Set 1-2


Question 1
What does an empty class contain?

Default constructor
Copy constructor
Address of operator
All of the above

Question 2
In protected derivation

Protected and public members of base class become protected
Private, protected and public members of base class become protected
Private, protected and public members of base class become private
Protected and public members of base class become private

Question 3
What is the output of the program?
#include <iostream.h>
void main()
{
int j = 20, k = 30;
int & m = j;
int * n = &j;
cout << j << " " << k << " " << m << " ++ " ;
m = k;
cout << j << " " << k << " " << m << " ++ ";
n = &k; // n now points to k
cout << j << " " << k << " " << m << " " << *n << endl;
}

20 30 20 ++ 20 30 30 ++ 30 30 30 30
20 30 20 ++ 30 30 30 ++ 20 30 30 30
20 30 20 ++ 20 30 30 ++ 20 30 30 30
20 30 20 ++ 30 30 30 ++ 30 30 30 30

Question 4
Class istream in iostream.h is defined as
Class istream : public ios
Class istream : public virtual ios
Class istream : public iostream
Class istream : public virtual iostream

Question 5
Interface contains

At least one pure virtual function
No pure virtual function
All pure virtual functions
None of the above

Question 6
What is the size of empty class?

0 bytes
2 bytes
1 byte
4 bytes

Question 7
The advantage of defining a pure virtual member function in a class is

Derived class may implement the pure virtual function
Derived class must implement the pure virtual function
Derive class is abstract class if it does not implement the pure virtual function
Both B and C

Question 8
What is the output of the following?

#include
void main()
{
int x, y;
x=(3, 4, 5);
y=3, 4, 5;
cout << endl << x <<" "<< y;
}
Compilation Error
3 5
3 3
5 3

Question 9
What is the output of the following?
#include <iostream.h>
void main ()
{
{
for(int x=1; x <= 5; x++, x+=5);
}
cout << endl << " value of x = " << x;
}

6
7
compilation error
2

Question 10
What is the output of the following?
#include <iostream.h>
void main ()
{
cout << (cout<<" Hello ") << " world ";
}

No output is displayed
Hello some_address_value world
Hello world
compilation error

Question 11
The class fstreambuf serves as base class for

ifstream, ofstream, fstream
ifstream, ofstream
ostream
ifstream

Question 12
The scope resolution operator permits

Access to an identifier in the global scope that has been hidden by another identifier with the same name in the local scope
Access to an identifier in the global space
Access to an identifier in the local scope
Access to an identifier in the local scope and global scope

Question 13
The declaration
void func_name( )
accepts

Any no of arguments
Only one argument
No Arguments
None of the above

Question 14
The technique of allocating memory during runtime on demand is known as

Dynamic binding
Dynamic memory allocation
Late binding
Template

Question 15
What is the output of the following?
#include
void main()
{
enum col {red, blue, yellow};
col c = blue << 1;
cout << c;
}

1
2
3
4

Question 16
The advantage of defining a pure virtual member function in a class is

Derived class may implement the pure virtual function
Derived class must implement the pure virtual function
Derive class is abstract class if it does not implement the pure virtual function
Both B and C

Question 17
Input and output operators are known as

extraction and insertion
get from and put to
Both A and B
None of the above

Question 18
A file can be tied to your program by defining an instance of

fstream
ifstream
ofstream
All of the above

Question 19
Which of the following is not true about constructor

constructor can be overloaded
constructor return type is int
constructor has the same name as the class in which it is defined
constructor are used for initializing data members

Question 20
What is the output of the program?

#include <iostream.h>
char *buf1 = "Genesis", *buf2 = "InSoft";
void main()
{
const char *p = buf1;
p = buf2;
*p = 'g';
cout << *p;
}
What is the output of the program?
g
genesis
No ouput is displayed
l-value specifies constant object

Answers
Answer 1 - D
Answer 2 - A
Answer 3 - D
Answer 4 - B
Answer 5 - C
Answer 6 - C
Answer 7 - D
Answer 8 - D
Answer 9 - C
Answer 10 - B
Answer 11 - A
Answer 12 - A
Answer 13 - C
Answer 14 - C
Answer 15 - B
Answer 16 - D
Answer 17 - C
Answer 18 - D
Answer 19 - B
Answer 20 - D
======================================================================
C++ Question Bank 03 / FAQs [20 QUESTIONS]

Question 1
Which of the following statements is true?

A constant member function does allow changes to any data members in the class
A static member functions allows access to non-static data
The size of the object is the sum of size of all non-static data
The size of a struct variable is the sum of size of all static and all non-static data


Question 2
What is the output of the following?

#include
void main()
{
int x = 20;
int &t = x;
x = 50;
cout << x << " " << t;
}

20 50
50 20
50 50
None of the above

Question 3
Friend function adds flexibility to the language, but they are controversial

Because it goes against the rule of data encapsulation
Because it can access a class's private data
Both A and B
None of the above

Question 4
Which of the following is true about a destructor?

Destructor like a constructor can accept arguments
Destructor can be overloaded
Destructor function is the same name as a class which is preceded by the tilde character
Destructor return type is void


Question 5
The prototype of output operator in the class "test" is as follows

friend ostream & operator << (ostream &, test &)
ostream & operator << (ostream &, test &)
friend ostream & operator << (test &)
friend ostream & operator << (ostream &)

Question 6
Which of the following statements is false?

Friend functions take one argument more than a member function
Operator overloading allows us to create new operators
Static member functions can access only static data
A constant cannot be changed


Question 7
Which of the following statements is true?

We cannot overload operator new and operator delete
Each instance of a class has a different copy of static data
We need to define in every class a constructor and destructor
class istream extends class ios

Question 8
What is the output of the following?

#include <iostream.h>
int add(int, int = 5, int = 10);
void main() {
cout << add(10) << " " << add(10, 20) << " " << add(10, 20, 30);
}

int add(int a, int b, int c)
{
return a + b + c;
}

compilation error
25 40 60
15 30 60
20 40 60


Question 9
To turn overloading off, which of the statements is used?

extern "C"
static "C"
Register "C"
off "C"


Question 10
The keywords related to exception handling are?

test, catch
try, throw, catch
namespace, catch
try, finally


Question 11
Genericity is a technique to

Defining software components that have more than one interpretation depending on the data type of parameter.
Which allows the extension of the functionality of the existing software components.
To derive a class from more than one base class.
Of creating new data types that are well suited to an application.

Question 12
Comments are

Integral part of the program and they do nothing
Integral part of the program and they help in coding and maintenance
Are not part of the program
Are not part of the program and they slow down the execution speed

Question 13
C++ does not support the following feature?

Multiple inheritance
Polymorphism
Operator overloading
Automatic memory management

Question 14
What is the output of the program?

#include <iostream.h>
char *buf1 = "Genesis", *buf2 = "InSoft";
void main()
{
char* const q=buf1;
*q='x';
cout << *q;
}

x
xenesis
l-value specifies constant object
None of the above

Question 15
What happens when new operator is called?

It invokes operator new, then invokes the constructor and then does type casting
It invokes the constructor, calls operator new and then does type casting
It invokes operator new and then invokes the constructor
It invokes the constructor and then does type casting

Question 16
Which keyword violates data encapsulation?

Public
Virtual
Friend
Protected

Question 17
Which of the following is not true about destructor?

Destructor can be overloaded
A destructor class member function is typically used to return dynamically allocated memory
A destructor function has the same name as the class in which it is defined preceded by the tilde character
A destructor does not have any return type

Question 18
What is the output of the program?

#include <iostream.h>
void main()
{
int val = 5;
int &val1 = val;
int &val2;
cout << val1;
}

5
val2 - references must be initialized
Address of variable val is printed
None of the above

Question 19
What happens when delete operator is called?

It invokes operator delete and then invokes the destructor if any
It invokes the destructor if any and then calls operator delete
It invokes operator delete
It invokes the destructor if any

Question 20
Which of the following are true about default arguments?

Default arguments must be the last argument
A default argument cannot be redefined in later declarations even if the redefinition is identical to the original
Additional default arguments can be added by later declarations
All of the above

Answers
Answer 1 - C
Answer 2 - C
Answer 3 - C
Answer 4 - C
Answer 5 - A
Answer 6 - B
Answer 7 - D
Answer 8 - B
Answer 9 - A
Answer 10 - B
Answer 11 - A
Answer 12 - B
Answer 13 - D
Answer 14 - A
Answer 15 - A
Answer 16 - C
Answer 17 - A
Answer 18 - B
Answer 19 - A
Answer 20 - D
powered by IT Jobs Posting