0% found this document useful (0 votes)
717 views22 pages

Ecp Mock

The document contains 32 multiple choice questions related to C programming. It tests knowledge of basic C concepts like data types, operators, control flow, functions, pointers, arrays, structures, unions, file handling and more. The questions have single correct answers related to predicting the output of code snippets or identifying valid syntax and semantics.

Uploaded by

pavan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
717 views22 pages

Ecp Mock

The document contains 32 multiple choice questions related to C programming. It tests knowledge of basic C concepts like data types, operators, control flow, functions, pointers, arrays, structures, unions, file handling and more. The questions have single correct answers related to predicting the output of code snippets or identifying valid syntax and semantics.

Uploaded by

pavan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

❖ ECP_MOCK_TEST

===============================

1. #include <stdio.h>

int main(void)

int num = 100;

int result = printf("%d",num) + num++;

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

return 0;

Answers

1. 100 102

2. 100 104

3. 100 103

4. 100 101

==============================================================================

2. #include <stdio.h>

int main(void)

int num1=0,num2=1;

int result;

result = ++num1 && --num2 && ++num1; printf("%d,%d,%d",num1,num2,result);

return 0;

}
Answers

1. 1,0,0

2. 1,0,1

3. 1,1,0

4. 1,1,1

====================================================================

3. What will be the o/p of the following code? #include <stdio.h>

int main(void)

int result=0;

int var1 = 10;

int num=10;

result+= var1++ + num++;

printf("%d",result);

return 0;

1. 21

2. 22

3. 20

4. 23

======================================================================

4. #include <stdio.h>

int main(void)

int i = 0;
if (i == 0)

i++;

continue;

printf("Sunbeam");

printf("%d",i);

return 0;

1. Sunbeam will print 1 times

2. Sunbeam will print infinite times

3. Compile Time Error

4. Sunbeam will print 0 times

==============================================

5. What will be the o/p of the following code? #include <stdio.h>

int main(void)

int i = 0;

for (; i < 3; i++);

printf("%d] sunbeam\t",i++);

return 0;

1. Compile Time Error

2. 0] Sunbeam 1] Sunbeam

3. Runtime Error
4. 3] Sunbeam

==============================================================================

6. The Statement extern int var is?

Answers

1. Defination of identifier var

2. Declaration of identifier var

3. Declaration as well as defination

4. None of the above

================================

7. What will be the o/p of the following code? #include<stdio.h>

int i;

void fun( void );

int main(void)

static int i=0;

fun();

fun();

fun();

printf("%d",i);

return 0;

void fun( void )

i++;
}

Answers

1. Garbage

2. 0

3. 3

4. Compile time error

======================================================================

8. In the following defination what is constant? const int const * ptr;

Answers

1. value is constant

2. pointer is constant

3. Both value and pointer are constant

4. Compile time error

===========================================

9. What will be the o/p of the following code? #include<stdio.h>

int main()

int arr[5] = {1,2,3,4,5};

printf("%d",(arr+1)[3]);

Answers

1. 5

2. 4

3. 2

4. Compile time error


==============================================================================

10. What will be the o/p of the following code? #include<stdio.h>

int main()

int arr[5] = {1,2,3,4,5};

int *ptr = arr;

ptr++;

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

Answers

1. 1

2. 3

3. 2

4. Garbage

==============================================

11. What will be the o/p of the following code? #include<stdio.h>

int main()

int result;

char name[8] = "Sunbeam";

char name2[8]={'S','U','N','B','E','A','M','\0'};

result = strcmp(name,name2);

if(result==0)

printf("same");

else
printf("not same");

Answers

1. not same

2. same

3. Compile time error

4. Runtime Error

==========================================================================

12. What will be the o/p of the following code? #include<stdio.h>

int main()

char name[10] ="Sunbeam";

char name2[10]; strcpy(name,strcpy(name2,strcpy(name,name+3)));

puts(name);

Answers

1. Sun

2. beam

3. Garbage

4. Compile time error

====================================================

13. What will be the o/p of the following code? #include<stdio.h>

int main()

int arr[2][2]={{1,2},{4,5}};
int i,j;

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

for (j = 0; j < 2; ++j)

printf("%d %d %d %d\n",i,j,*(*(arr+i)+j),*(*(arr+i)+j));

return 0;

Answers

1. 0 0 1 1 0 1 1 2 1 0 4 5 1 1 0 0

2. 0 0 1 1 0 1 2 4 1 0 4 5 1 1 5 5

3. 0 0 1 1 0 1 2 2 1 0 4 4 1 1 5 5

4. 0 0 1 1 0 1 2 2 1 0 4 5 1 1 5 4

=====================================================

14. What will be the o/p of the following code? #include<stdio.h>

int main(void)

int arr[3][3] = {{1,2,3},{4,5,6},{7,8,9}};

int i,j;

int *ptr;

ptr = (int*)&arr+1;

ptr++;

printf("%d",*ptr);
return 0;

Answers

1. 1

2. 3

3. Garbage

4. 4

========================================================

15. Which of the following is/are true

Answers

1. calloc() allocates the memory and also initialise the allocated memory to zero,

2. Memory allocated using malloc() has random data.

3. calloc() takes two arguments, but malloc takes only 1 argument.

4. All of the above

================================================================

16. What will be the output of following code? #include <stdio.h>

void func(int var,int num)

printf("%d %d",var++,--num);

void main()

int p=3, q=1;

func(p,p);

printf("%d %d ",p++,--q);
}

Answers

1. 3 2 3 0

2. 3 2 3 2

3. 3 2 3 1

4. 2 3 2 3

========================================================

17. What will be the o/p of the following code? #include<stdio.h>

struct bit {

int a:1;

unsigned int b:2;

};

int main(void)

struct bit b1;

b1.b =5;

printf("%d",b1.b);

printf(" %d",sizeof(b1));

return 0;

Answers

1. 1 4

2. 2 8

3. garbage 8

4. 2 4
=======================================================

18. What will be the o/p of the following code? #include<stdio.h>

#define cal(a) a * 5 / a

int main( void )

int z = cal(1+2) * 5;

printf("%d",z);

return 0;

Answers

1. 10

2. 21

3. 5

4. 11

===============================================================

19. What will be the o/p of the following code? #include<stdio.h>

#include<string.h>

struct Test { char str[10]; };

int main(void)

struct Test st1, st2;

strcpy(st1.str, "Pune");

st2 = st1; st1.str[0]='K';

printf("%s %s",st2.str,st1.str);

return 0;
}

Answers

1. Kune Kune

2. Pune Kune

3. Pune Garbage

4. Pune Pune

===========================================================

20. What will be the o/p of the following code? #include<stdio.h>

#pragma pack(1)

typedef union {

char ch;

float fvar;

struct { int number; double d1; }s1;

}D1;

int main()

printf("%d",sizeof(D1));

return 0;

Answers

1. Compile time Error

2. 16

3. 24

4. 12

=======================================================
21. What will be the output of following program ? #include<stdio.h>

enum menu { a=2,b,c,d=-1,e};

enum menu m;

int main()

printf(“%d %d”,b+a,e+d);

Answers

1. 2 3

2. 0 1

3. 5 -1

4. Error

=============================================================

22. What will be the output of following program ? #include<stdio.h>

int main()

char ch;

if((~sizeof(ch) + !sizeof('A'))) printf("Hinjewadi");

else

printf("MarketYard");

return 0;

Answers

1. MarketYard

2. Hinjewadi
3. NO OUTPUT

4. Hinjewadi MarketYard

===============================================================

23. What will be the output of following program ? #include<stdio.h>

int main()

char ch = 65;

switch(++ch)

case 'A': printf("Hinjewadi\n"); break;

case 'B': printf("MarketYard\n");

default: printf("Karad\n"); break;

return 0;

Answers

1. MarketYard Karad

2. Karad

3. Hinjewadi

4. Compile Time Error

===================================================================

24. What is the output of the following code? #include<stdio.h>

void main()

int s=0;
while(s++<10)

if(s<4 && s<9)

continue;

printf(“\n%d\t”,s);

Answers

1. 1 2 3 1 0

2. 4 5 6 7 8 9

3. 4 5 6 7 8 9 10

4. 1 2 3 4 5 6 7 8 9

========================================================

25. Output?

#include <stdio.h>

int main()

int c = 5, no = 10;

do {

no /= c;

} while(c--);

printf ("%dn", no);

return 0;

Answers
1. 1

2. Runtime Error

3. 0

4. Compiler Error

============================================================

26. what will be the output of this code?

#include <stdio.h>

int main()

int i,x=10; i=abc(++x);

printf("%d",--i);

return 0;

int abc(int i)

{ return(i++); }

Answers

1. 10

2. 9

3. 11

4. none of the above

===================================================

27. What will be the o/p of the following code If P is a pointer to an integer and T is a pointer to a
character then scale factor of P will be

Answers

1. same as that of scale factor of T

2. greater than that of scale factor of T


3. less than that of scale factor of T

4. None of the above

=============================================================

8. What will be the o/p of the following program if i/p is given as

<programname> monday tuesday wednesday

#include<stdio.h>

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

int i =0;

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

printf("%s\n",argv[i]); argv++;

return 0;

Answers

1. programname wednesday

2. programname tuesday

3. Runtime Error

4. programname monday

===================================================

29. What is the return type of malloc() or calloc()?

Answers

1. int *
2. int **

3. void *

4. void **

================================================================

30. Which of these are valid declaration?

i) union { int I; int j;};

ii) union u_tag { int I; int j;} u;

iii)union { int I; int j; FILE *K;}u;

iv) union { int I; int j;} u;

Answers

1. All are correct

2. Option (i), (ii),and(iv)

3. Option (ii),(iii) and (iv)

4. Option (ii)only

===============================================================

31. What is the correct syntax to declare bit-field in structure?

Answers

1. struct temp { unsigned int a : 1; }s;

2. struct temp { unsigned int a = 1; }s;

3. struct temp { unsigned float a : 1; }s;

4. None of the mentioned

=========================================================

32. What is the purpose of "rb" in fopen() function used below in the code?

FILE *fp;fp = fopen("sunbeam.txt", "rb");

Answers
1. Open "sunbeam.txt" in binary mode for reading

2. Create a new file "sunbeam.txt" for reading and writing

3. Open "sunbeam.txt" in binary mode for reading and writing

4. None of the above

========================================================

33. What is output of following Code?

int main()

int a,b,c; a=4; b=2;

c=~(a^b / a<<b);

printf("%d",c);

Answers

1. 5

2. 10

3. -5

4. -10

===============================================

34. In the following code what is 'sunbeam'?typedef char *charp; const charp sunbeam;

Answers

1. sunbeam is a constant

2. sunbeam is a character constant

3. sunbeam is character type

4. None of above

====================================================
35. int main()

typedef int f;

f *fptr;

int fval = 98;

fptr = &fval;

printf("%f\n", *fptr);

return 0;

Answers

1. 10

2. 97

3. 98

4. 0

=============================================

36. What is makefile?

Answers

1. makefile describes to the make command that how to compile the program

2. makefile contains various statements related with the compilation of target

3. makefile contains various statements

4. none of the mentioned

====================================================

37. Which of the following best describe volatile keyword?

Answers

1. Volatile keyword indicates that the variable is stored in volatile memory


2. Volatile keyword indicates that the value of the variable cannot be determined at compile time

3. Volatile keyword instruct the compiler not to do any optimization on that variable

4. Volatile keyword indicates that it cannot be used with const keyword

==========================================================

38. #include <stdio.h>

struct bitfield { int y : 2; char x : 2; };

int main()

struct bitfield p;

p.x = 2; p.y = 1; p.x = p.x & p.y;

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

return 0;

Answers

1. 0

2. 1

3. 2

4. Error

==============================================================

39. When fopen() gets failed to open the file, it returns ___________ .

Answers

1. EOF

2. NULL

3. Run time error caused

4. None of the above


==========================================================

40. Which of the following is/are calling convention?

Answers

1. cdecl

2. pascal

3. stdcall

4. all of the above

================================

You might also like