0% found this document useful (0 votes)
82 views

TCS _ MCQ_Technical

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

TCS _ MCQ_Technical

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

1. Can we declare function inside structure of C Programming?

(a) Yes (b) No


(c) Depends on Compiler (d) Yes but run time error

2. What is storage class for variable A in below code?


void main()
{
int A;
A = 10;
printf("%d", A);
}
(a) extern (b) auto (c) register (d) static

3. What is output of below program?


void main()
{
const int a = 10;
printf("%d",++a);
}
(a) 11 (b) 10
(c) Compilation Error (d) 0

4. Library function pow() belongs to which header file?


(a) mathio.h (b) math.h
(c) square.h (d) stdio.h

5. Libray function getch() belongs to which header file?


(a) stdio.h (b) conio.h (c) stdlib.h (d) stdlibio.h

6. What is the following is invalid header file in C?


(a) math.h (b) mathio.h (c) string.h (d) ctype.h

7. What is output of below code?


void main()
{
char name[]="Cppbuz";
int len;
int size;
len = strlen(name);
size = size_of(name);
printf("%d,%d",len,size);
}
(a) 6, 6 (b) 6, 7 (c) 7, 7 (d) 0, 0

8. The concept of two functions with same name is known as?


(a) Operator Overloading (b) Function Overloading
(c) Function Overriding (d) Function renaming

9. What is the meaning of below lines?


void sum (int, int);
(a) It is function definition of sum which takes int arguments

Page 1 of 33
(b) It is a function declaration of sum which takes int arguments and returns void
(c) It is a function call of sum that sends two arguments
(d) Can't comment

10. When C Language was invented?


(a) 1970 (b) 1972 (c) 1978 (d) 1979

11. How many loops are there in C?


(a) 2 (b) 3 (c) 4 (d) 1

12. What is output of below program?


void main()
{
for(; ;)
for(; ;)
printf("Hello..");
}
(a) Compilation Error
(b) Runtime Error
(c) Hello is printed one time
(d) Hello is printed infinite times

13. What is output of below program?


void main()
{
int i;
clrscr();
for(i = 0,i<5,i++)
{
printf("Hello");
}
}
(a) Hello is printed 5 times (b) Compilation Error
(c) Runtime Error (d) Hello is printed 4 times

14. What is output of below program?


void main()
{
int i;
for(i=0; i<=5; ++i)
{
printf("Hello");
break;
}
}
(a) Hello is printed 5 times (b) Compilation Error
(c) Hello is printed 6 times (d) Hello is printed 1 time

15. What is output of below program?


void main()
{
int i,j;
for(i = 0,j=0;i<5;i++)
{
printf("%d%d--",i,j);
}
}
(a) 0--01--12--23--34--
(b) 00--10--20--30--40--
(c) Compilation Error
(d) 00--01--02--03--04--

16. What is output of below program?


void main()
{
int i,j,k,count;
count=0;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
count++;
}
}
printf("%d",count);
}
(a) 5 (b) 10 (c) 25 (d) 50

17. What is output of below program?


void main()
{
int i;
for(i=1; i<5; i++);
{
printf("cppbuzz");
}
}
(a) cppbuzz is printed 5 times
(b) Compilation Error
(c) cppbuzz is printed 1 times
(d) cppbuzz is printed 4 times

18. What is printed on console?


void main()
{
int a = 0;
while(a)
{
printf("CppBuzz.com");
}
}
(a) CppBuzz.com is printed Infinite times
(b) CppBuzz.com is printed 1 time only
(c) Nothing is printed
(d) Program gives error

19. How many times CppBuzz.com is printed on console?


void main()
{
int a = 0;
while(a==0)
{
printf("CppBuzz.com");
}
}
(a) 0 times
(b) Infinite times (Untill Stack is overflow)
(c) 1 time
(d) Nothing is printed

20. How many times ‘C Programming’ is printed on console?


void main()
{
int a = 2;
while(a++<=2)
{
printf(“C Programming");
}
}
(a) 0 times
(b) 3 times
(c) 1 time
(d) Infinite times (Until Stack overflow)

21. Find the output of the following program.


int main()
{
int x;
x=10,20,30;
printf("%d",x);
return 0;
}
(a) 10 (b) 20
(c) 30 (d) Compilation Error

22. Find the output of the following program.


int main()
{
int x;
x=(10,20,30);
printf("%d",x);
return 0;
}
(a) 10 (b) 20
(c) 30 (d) Compilation Error

23. Find the output of the following program.


int main()
{
int a = 320;
char *ptr;
ptr =( char *)&a;
printf("%d",*ptr);
return 0;
}
(a) 320 (b) 60 (c) 160 (d) 64

24. Find the output of the following program.


int main()
{
char arr[5]="ALL THE BEST";
printf("%s",arr);
return 0;
}
(a) ALL THE BEST (b) ALL T
(c) Runtime error (d) Compilation Error

24. Find the output of the following program.


void main()
{
int a = 10.5;
printf("%d",a);
}
(a) 10.5 (b) 10
(c) 0 (d) Compilation Error

25. Find the output of the following program.


void main()
{
int a = printf ("Hello to all\n");
printf("%d", a);
}
(a) Compilation Error
(b) Hello to all
2
(c) Hello to all
(d) No output

26. Which programming language is more faster among these?


(a) Java (b) Php
(c) C (d) Visual Basic
27. What is the output of this program given that it is compiled on a 32 bit device?
int main()
{
char *ptr1, *ptr2;
printf("%d %d", sizeof(ptr1), sizeof(ptr2));
return 0;
}
(a) 1 1 (b) 2 2
(c) 4 4 (d) Undefined

28. Find the output of the following program.


main()
{
int x = 10;
{
int x = 0;
printf("%d",x);
}
}
(a) 10 (b) Compilation Error
(c) 0 (d) Garbage value

29. Find the output of the following program.


int main()
{
extern int i;
i = 20;
printf("%d", sizeof(i));
return 0;
}
(a) 20 (b) 0
(c) Undefined reference to i (d) Linking Error

30. What is sizeof() in C?


(a) Operator (b) Math Function
(c) Macro (d) Variable name

31. How many main() function we can have in our project?


(a) 1 (b) 2
(c) No Limit (d) Depends on Compiler

32. Is it possible to return two values by any function using the return keyword?
(a) Yes (b) No

33. Find the output of the following program.


#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int a = atoi("100");
printf("%d",a);
return 0;
}
(a) 0 (b) 1 (c) 100 (d) 3

34. Find the output of the following program.


#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
char buffer[4];
atoi(123, buffer, 10);
printf("%s", buffer);
return 0;
}
(a) 1234 (b) 12340 (c) Error (d) 0

35 Find the output of the following program.


#include <stdio.h>
char * f();
char a = 'a';
int main(int argc, char *argv[])
{
char *temp = f();
printf("%s", temp);
return 0;
}
char *f()
{ return &a;
}
(a) a (b) ASCII value of a
(c) Address of character a (d) Compilation Error

36. Numbers are stored and transmitted inside a computer in which format?
(a) binary form (b) ASCII code form
(c) decimal form (d) hexadecimal form

37. The ASCII code of ‘A’ is?


(a) 66 in Decimal (b) 41 in hexadecimal
(c) 0100 0010 in binary (d) 0110 0011 in binary

38. Which compilation unit is responsible for adding header files content in the source code?
(a) Linker (b) Compiler
(c) Assembler (d) Preprocessor

39. Which one of the following is invalid pre-processor directive in C programming?


(a) #pragma (b) #error (c) #endif (d) #elseif

40. Will compiler produce any compilation error if same header file is included two times?
(a) Yes (b) No

41. What is the job of Assembler in C programming?


(a) It converts source code into assembly code
(b) It converts an assembly language program into machine language
(c) It converts code generated by Preprocessor to assembly code
(d) None of these
42. Which macro is used to insert assembly code in C program (GCC compiler)?
(a) __asm__ (b) _asm_ (c) __asm (d) asm

43. Find the output of the following program.


#include <stdio.h>
int main()
{
int a;
if(a = printf("Exam time-"))
{
printf("Wake up early");
}
else
{
printf("Sleep late");
}
return 0;
}
(a) Exam time – Wake up early
(b) Exam time – Sleep late
(c) Wake up early Sleep late
(d) Compiler error

44. Find the output of the following program.


#include<stdio.h>
int main()
{
int @a = 10;
printf("%d",@a);
return 0;
}
(a) 10 (b) @10
(c) @@10 (d) Compilation Error

45. Find the output of the following program.


#include<stdio.h>
int a = 20;
int main()
{
int a = 10;
printf("%d", ::a);
return 0;
}
(a) 10 (b) 20
(c) Invalid operator :: (d) Error Re-declaration of a

46. Find the output of the following program.


#include<stdio.h>
int main()
{
int a = 10;
printf("%d ", a);
int a = 20;
printf("%d",a);
return 0;
}
(a) 10 20 (b) 10 10
(c) 20 20 (d) Error: Re-declaration of a

47. Find the output of the following program.


#include<stdio.h>
int main()
{
int a@ = 10;
printf("%d", a@);
return 0;
}
(a) 10
(b) 10@
(c) @10@
(d) [Error] stray '@' in program

48. Find the output of the following program.


#include<stdio.h>
#include<string.h>
int main()
{
char arr[] = "Welcome to Smart";
printf("%d-%d",sizeof(arr), strlen(arr));
return 0;
}
(a) 16-16 (b) 4-16 (c) 17-16 (d) 17-17

49. What will be the output of this program given that it is compiled in a 32 bit compiler?
#include<stdio.h>
#include<string.h>
int main()
{
char arr[] = "C Aptitude";
arr[0]++;
++arr[0];
printf(“%s”, arr);
return 0;
}
(a) C (b) E Aptitude
(c) Compilation error (d) Some garbage numbers

50. Find the output of the following program.


#include<stdio.h>
#include<string.h>
int main()
{
struct xyz{
char * n;
int eos;
};
struct xyz x = {"Smart Training", 2018};
struct xyz y=x;
printf("%i", printf("%s",y.n));
return 0;
}
(a) Smart Training 14 (b) Smart Training 2
(c) Compiler error (d) Smart Training 16

ANSWER KEY

1. Ans: [b] 2. Ans: [b] 3. Ans: [c] 4. Ans: [b]

5. Ans: [b] 6. Ans: [b] 7. Ans: [b] 8. Ans: [b]

9. Ans: [b] 10. Ans: [b] 11. Ans: [b] 12. Ans: [d]

13. Ans: [b] 14. Ans: [d] 15. Ans: [b] 16. Ans: [c]

17. Ans: [c] 18. Ans: [c] 19. Ans: [b] 20. Ans: [c]

21. Ans: [a] 22. Ans: [c] 23. Ans: [d] 24. Ans: [b]

24. Ans: [b] 25. Ans: [d] 26. Ans: [c] 27. Ans: [c]

28. Ans: [c] 29. Ans: [c] 30. Ans: [a] 31. Ans: [a]

32. Ans: [b] 33. Ans: [c] 34. Ans: [c] 35 Ans: [a]

36. Ans: [a] 37. Ans: [b] 38. Ans: [d] 39. Ans: [d]

40. Ans: [b] 41. Ans: [b] 42. Ans: [a] 43. Ans: [a]

44. Ans: [d] 45. Ans: [b] 46. Ans: [d] 47. Ans: [d]

48. Ans: [c] 49. Ans: [d] 50. Ans: [d]

C–MCQs
51. What is the output of this C code?
#include <stdio.h>
void main()
{
struct student
{
int no;
char name[20];
};
struct student s;
no = 8;
printf("%d", no);
}
(a) 8 (b) Junk
(c) Nothing (d) Compile time error
52. Which of the following is a User-defined data type?
(a) typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays;
(b) typedef int Boolean;
(c) struct {char name[10], int age};
(d) All of the mentioned
SOLUTION:
typedef and struct are used to define user-defined data types.
53. What is the output of this C code?
#include <stdio.h>
int main()
{
void foo();
printf("1 ");
foo();
}
void foo()
{
printf("2 ");
}
(a) 1 2
(b) 1 2 1 2
(c) Compile time error
(d) Depends on the compiler
54. What is the output of this C code?
#include <stdio.h>
int main()
{
int i = 0, j = 0;
for (i; i < 2; i++){
for (j = 0; j < 3; j++){
printf("1\n");
break;
}
printf("2\n");
}
printf("after loop\n");
}
(a) 1
after loop
(b) 1
2
after loop
(c) 1
2
1
2
after loop
(d) 1
1
2
after loop
55. Relational operators cannot be used on:
(a) strings (b) long
(c) float (d) structure
56. What is the output of this C code?
#include <stdio.h>
void main()
{
int b = 5 & 4 & 6;
printf("%d", b);
}
(a) 3 (b) 4 (c) 5 (d) 6
57. Which of the following function declaration is illegal?
(a) int main()
{
double func();
}
double func(){//statements}
(b) double func();
int main(){}
double func(){}
(c) double func(){};
int main(){}
(d) None of the mentioned
58. What is the scope of an external variable?
(a) Whole source file in which it is defined
(b) From the point of declaration to the end of the file being compiled
(c) From the point of declaration to the end of the file in which it is defined
(d) Any source file in a program
59. The maximum number of arguments that can be passed in a single function are_____________
(a) 127
(b) 253
(c) 361
(d) No limits in number of arguments
60. What is the output of this C code?
#include <stdio.h>
void main()
{
int b = 5 + 7 * 4 - 9 * (3, 2);
printf("%d", b);
}
(a) 21 (b) 15 (c) 13 (d) 6
61. What is the output of this C code?
#include <stdio.h>
void main()
{
double b = 5 % 3 & 4 + 5 * 6;
printf("%lf", b);
}
(a) 30
(b) 2.000000
(c) Run time error
(d) 2
62. What is the output of this C code?
#include <stdio.h>
void main()
{
int x = 1, y = 0, z = 5;
int a = x && y && z++;
printf("%d", z);
}
(a) 5 (b) Varies (c) 6 (d) 0
63. What is the output of this C code?
#include <stdio.h>
int main()
{
foo();
foo();
}
void foo()
{
int i = 11;
printf("%d ", i);
static int j = 12;
j = j + 1;
printf("%d ", j);
}
(a) 11 12 11 12 (b) Compile time error
(c) 11 13 11 14 (d) 11 12 11 13
64. What is the value of the below assignment expression
(x = foo())!= 1 considering foo() returns 2
(a) 0 (b) True (c) 2 (d) 1
65. What would happen if you create a file stdio.h and use #include “stdio.h” ?
(a) The predefined library file will be selected
(b) The user-defined library file will be selected
(c) The compiler won’t accept the program
(d) Both the files will be included
66. for c = 2, value of c after c <<= 1;
(a) c = 4; (b) c = 2; (c) c = 1; (d) c = 3;
67. What is the output of this C code?
#include <stdio.h>
int main()
{
int x = 3; //, y = 2;
const int *p = &x;
*p++;
printf("%d\n", *p);
}
(a) Undefined behaviour
(b) 4
(c) Some garbage value
(d) Increment of read-only location compile error
68. Comment on the output of this C code?
#include <stdio.h>
int main()
{
int i = 2;
int i = i++ + i;
printf("%d\n", i);
}
(a) = operator is not a sequence point
(b) None of these
(c) it can be evaluated as (i++)+i or i+(++i)
(d) ++ operator may return value with or without side effects
69. Variable names beginning with underscore is not encouraged. Why?
(a) To avoid conflicts since assemblers and loaders use such names
(b) To avoid conflicts with environment variables of an operating system
(c) It is not standardized
(d) To avoid conflicts since library routines use such names
70. What is the output of this C code (if run with no options or arguments)?
#include <stdio.h>
int main(int argc, char *argv[ ])
{
printf("%d\n", argc);
return 0;
}
(a) 0
(b) Depends on the platform
(c) 1
(d) Depends on the compiler
71. Comment on the output of this C code?
#include <stdio.h>
int main()
{
int a = 10;
int **c -= &&a;
}
(a) You cannot apply any arithmetic operand to a pointer.
(b) We don’t have address of an address operator
(c) Both of these
(d) None of these
72. The correct way to declare and assign a function pointer is done by:
(Assuming the function to be assigned is “int multi(int, int);”)
(a) int *fn_ptr(int, int) = multi;
(b) int *fn_ptr(int, int) = multi;
(c) int (*fn_ptr)(int, int) = multi;
(d) None of these
73. What is the size of *ptr in a 32-bit machine, (assuming initialization as int *ptr = 10;)?
(a) 8 (b) 4 (c) 1 (d) 2
74. What is the output of this C code?
#include <stdio.h>
int main()
{
short int i;
scanf("%h*d", &i);
printf("%hd", i);
return 0;
}
(a) Depends on the standard.
(b) Undefined behavior
(c) Some garbage value
(d) Compilation error
75. What is the output of the code below?
#include <stdio.h>
int main()
{
int i = 10;
int *const p = &i;
foo(&p);
printf("%d\n", *p);
}
void foo(int **p)
{
int j = 11;
*p = &j;
printf("%d\n", **p);
}
(a) Compile time error
(b) 11 Garbage Value
(c) Undefined behaviour
(d) Segmentation fault/code-crash
76. What is the output of this C code?
#include <stdio.h>
void main()
{
char *s = "hello";
char *n = "cjn";
char *p = s + n;
printf("%c\t%c", *p, s[1]);
}
(a) h e
(b) Compile time error
(c) h n
(d) c o
77. What is the output of this C code?
#include <stdio.h>
int main()
{
int one = 1, two = 2;
#ifdef next
one = 2;
two = 1;
#endif
printf("%d, %d", one, two);
}
(a) 1, 1 (b) 1, 2 (c) 2, 1 (d) 2, 2
78. What is the output of this C code?
#include <stdio.h>
void f(char *k)
{
k++;
k[2] = 'm';
printf("%c\n", *k);
}
void main()
{
char s[] = "hello";
f(s);
}
(a) e (b) h (c) o (d) l What is the output of this C code?
#include <stdio.h>
void main()
{
char a[10][5] = {"hi", "hello", "fellows"};
printf("%s", a[2]);
} What is the output of this C code?
#include <stdio.h>
void main()
{
char a[10][5] = {"hi", "hello", "fellows"};
printf("%s", a[2]);
}
79. Which among the following is odd one out?
(a) fprintf (b) printf (c) scanf (d) putchar
80. What is the output of this C code?
#include <stdio.h>
void main()
{
int k = 5;
int *p = &k;
int **m = &p;
printf("%d%d%d\n", k, *p, **p);
}
(a) Compile time error
(b) 5 5 junk value
(c) 5 junk junk
(d) 5 5 5
81. What is the output of this C code?
#include <stdio.h>
void main()
{
int k = 4;
float k = 4;
printf("%d", k)
}
(a) 4 (b) 4.4
(c) 4.0000000 (d) Compile time error
SOLUTION:
Since the variable k is defined both as integer and as float, it results in an error.
Output:
$ cc pgm8.c
pgm8.c: In function ‘main’:
pgm8.c:5: error: conflicting types for ‘k’
pgm8.c:4: note: previous definition of ‘k’ was here
pgm8.c:6: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘double’
pgm8.c:7: error: expected ‘;’ before ‘}’ token
82. What is the output of this C code?
#include <stdio.h>
int main()
{
int i = 0, j = 1;
int *a[ ] = {&i, &j};
printf("%d", (*a)[0]);
return 0;
}
(a) Undefined behaviour
(b) 0
(c) Some garbage value
(d) Compile time error
83. What is the output of this C code?
#include <stdio.h>
void foo(const int *);
int main()
{
const int i = 10;
printf("%d ", i);
foo(&i);
printf("%d", i);
}
void foo(const int *i)
{
*i = 20;
}
(a) 10 (b) 10 20
(c) Compile time error (d) Undefined value
SOLUTION:
Cannot change a const type value.
Output:
$ cc pgm1.c
pgm1.c: In function ‘foo’:
pgm1.c:13: error: assignment of read-only location ‘*i’
84. What is the output of this C code?
#include <stdio.h>
void main()
{
int x;
}
here x is
(a) register variable
(b) static variable
(c) automatic variable
(d) global variable.
85. What is the output of this C code?
#include <stdio.h>
int main()
{
foo();
foo();
}
void foo()
{
int i = 11;
printf("%d ", i);
static int j = 12;
j = j + 1;
printf("%d ", j);
}
(a) Compile time error
(b) 11 12 11 13
(c) 11 13 11 14
(d) 11 12 11 12
86. What is the output of this C code?
#include <stdio.h>
void main()
{
int x = 4, y, z;
y = --x;
z = x--;
printf("%d%d%d", x, y, z);
}
(a) 3 2 3 (b) 2 3 3 (c) 3 2 2 (d) 2 3 4
87. What is the output of this C code?
#include <stdio.h>
void main()
{
int b = 5 - 4 + 2 * 5;
printf("%d", b);
}
(a) None of the mentioned
(b) -5
(c) 25
(d) 11
88. What is the output of this C code?
#include <stdio.h>
int main()
{
int i = 0, j = 0;
l1: while (i < 2)
{
i++;
while (j < 3)
{
printf("loop ");
goto l1;
}
}
}
(a) loop loop
(b) Infinite loop
(c) Compile time error
(d) loop loop loop loop
89. What is the output of this C code?
#include <stdio.h>
int main()
{
int x = 0;
if (x == 1)
if (x >= 0)
printf("true\n");
else
printf("false\n");
}
(a) true
(b) No print statement
(c) Depends on the compiler
(d) false
90. What is the output of this C code?
#include <stdio.h>
#define MIN 0
#if MIN
#define MAX 10
#endif
int main()
{
printf("%d %d\n", MAX, MIN);
return 0;
}
(a) Undefined behaviour
(b) 10 0
(c) Compile time error
(d) None of the mentioned
91. What is the output of this C code?
#include <stdio.h>
int main()
{
int x = 2;
x = x << 1;
printf("%d\n", x);
}
(a) 1
(b) Depends on the compiler
(c) Depends on the endianness of the machine
(d) 4
92. For initialization a = 2, c = 1 the value of a and c after this code will be
c = (c) ? a = 0 : 2;
(a) a = 0, c = 0; (b) a = 2, c = 2;
(c) a = 1, c = 2; (d) a = 2, c = 2;
93. The second (argument vector) in command line arguments is
(a) A pointer to an array of character strings that contain the arguments, one per string.
(b) Nothing
(c) The number of command-line arguments the program was invoked with;
(d) None of these
94. What is the output of this C code?
#include <stdio.h>
#include <ctype.h>
int main()
{
int i = 9;
if (isdigit(i))
printf("digit\n");
else
printf("not digit\n");
return 0;
}
(a) Depends on the compiler
(b) digit
(c) None of the mentioned
(d) not digit
95. What is the output of this C code?
#include <stdio.h>
void main()
{
char a[10][5] = {"hi", "hello", "fellows"};
printf("%s", a[2]);
}
(a) fell (b) fellows
(c) fello (d) fellow
96. What is the output of this C code?
#include <stdio.h>
int main()
{
int a[4] = {1, 2, 3, 4};
void *p = &a[1];
void *ptr = &a[2];
int n = 1;
n = ptr - p;
printf("%d\n", n);
}
(a) 1
(b) Compile time error
(c) Depends on the compiler
(d) 4
97. What is the output of this C code?
#include <stdio.h>
void m(int p, int q)
{
int temp = p;
p = q;
q = temp;
}
void main()
{
int a = 6, b = 5;
m(a, b);
printf("%d %d\n", a, b);
}
(a) 6 5 (b) 6 6 (c) 5 5 (d) 5 6
98. What is the value of i and j in the below code?
#include <stdio.h>
int x = 0;
int main()
{
int i = (f() + g()) || g();
int j = g() || (f() + g());
}
int f()
{
if (x == 0)
return x + 1;
else
return x - 1;
}
int g()
{
return x++;
}
(a) i value is 1 and j value is undefined
(b) i and j value are undefined
(c) i value is 0 and j value is 0
(d) i value is 1 and j value is 1
99. What is the output of this C code?
#include <stdio.h>
int x = 5;
void main()
{
int x = 3;
printf("%d", x);
{
int x = 4;
}
printf("%d", x);
}
(a) 3 5 (b) 3 3
(c) Run time error (d) 3 4
100. What does this statement printf(“%10s”, state); means?
(a) None of the mentioned
(b) 10 spaces before the string state is printed
(c) Print empty spaces if the string state is less than 10 characters
(d) Print the last 10 characters of the string
101. What is the sequence for preprocessor to look for the file within < > ?
(a) The predefined location only
(b) The predefined location then the current directory
(c) The current directory then the predefined location
(d) The current directory location
102. Comment on the output of this C code?
#include <stdio.h>
#include "test.h"
#include "test.h"
int main()
{
//some code
}
(a) false
(b) Compile time error
(c) true
(d) Depends on the compiler
103. What is the output of this C code?
#include <stdio.h>
int main()
{
int i = 10;
void *p = &i;
printf("%f\n", *(float*)p);
return 0;
}
(a) 10
(b) Undefined behaviour
(c) 0.000000
(d) Compile time error
104. What is the output of this C code?
#include <stdio.h>
int main()
{
int a[4] = {1, 2, 3, 4};
int b[4] = {1, 2, 3, 4};
int n = &b[3] - &a[2];
printf("%d\n", n);
}
(a) 5
(b) – 3
(c) Compile time error
(d) 4
105. What is the output of this C code?
#include <stdio.h>
int main()
{
int var = 010;
printf("%d", var);
}
__________
Ans: 8
106. What is the output of this C code?
#include <stdio.h>
enum birds {SPARROW, PEACOCK, PARROT};
enum animals {TIGER = 8, LION, RABBIT, ZEBRA};
int main()
{
enum birds m = TIGER;
int k;
k = m;
printf("%d\n", k);
return 0;
}
__________
Ans: 8
107. What is the output of this C code?
#include <stdio.h>
#define MAX 2
enum bird {SPARROW = MAX + 1, PARROT = SPARROW + MAX};
int main()
{
enum bird b = PARROT;
printf("%d\n", b);
return 0;
}
__________
Ans: 5
108. What is the output of this C code?
#include <stdio.h>
int main()
{
printf("Placementseason\rclass\n");
return 0;
}
_____
Ans: classmentseason
109. What is the output of this C code?
#include <stdio.h>
void main()
{
int x = 0, y = 2, z = 3;
int a = x & y | z;
printf("%d", a);
}
__________
Ans: 3
110. Number of bytes in memory taken by the below structure is
#include <stdio.h>
struct test
{
int k;
char c;
};
(a) Multiple of word size
(b) Multiple of integer size
(c) integer size+character size
(d) Depends on the platform
111. What is the output of this C code?
#include <stdio.h>
int main()
{
int i = 0;
char c = 'a';
while (i < 2){
i++;
switch (c) {
case 'a':
printf("%c ", c);
break;
break;
}
}
printf("after loop\n");
}
(a) None of the mentioned
(b) a a after loop
(c) after loop
(d) a after loop
112. The following code ‘for(;;)’ represents an infinite loop. It can be terminated by.
(a) All of the mentioned
(b) abort()
(c) break
(d) exit(0)
113. What is the correct syntax to send a 3-dimensional array as a parameter?
(Assuming declaration int a[5][4][3];)
(a) func(a);
(b) func(&a);
(c) func(*a);
(d) func(**a);
114. What is the final value of j in the below code?
#include <stdio.h>
int main()
{
int i = 10, j = 0;
if (i || (j = i + 10))
//do something
;
}
________
Ans: 0
115. What is the output of this C code?
#include <stdio.h>
int main()
{
int i = 1;
if (i++ && (i == 1))
printf("Yes\n");
else
printf("No\n");
}
__________
Ans: No
116. Are logical operators sequence points?
_________
Ans: True
117. What is the output of this C code?
#include <stdio.h>
int main()
{
int a = 1, b = 2;
a += b -= a;
printf("%d %d", a, b);
}
_________
Ans: 2 1
118. Value of c after the following expression (initializations a = 1, b = 2, c = 1):
c += (-c) ? a : b
_________
Ans: c=2
119. What is the size of array “line” used in fgets(line, maxline, *fp) function?
(a) maxline
(b) maxline + 1
(c) maxline – 1
(d) Size is dynamic
120. Which of the following is the correct syntax for calling function ungetc?
Assume int c and FILE *fp
(a) ungetc(*fp,c);
(b) ungetc(c, fp);
(c) ungetc(fp, c);
(d) ungetc(c,*fp);
121. stderr is similar to?
(a) stdin
(b) None of the mentioned
(c) Both stdout and stdin
(d) Stdout
122. What is the output of this C code?
#include <stdio.h>
int main()
{
char *str = "hello, world";
char *str1 = "hello, world";
if (strcmp(str, str1))
printf("equal");
else
printf("unequal");
}
(a) Compilation error
(b) Depends on the compiler
(c) unequal
(d) equal
123. Which pre-defined function returns a pointer to the last occurence of a character in a string?
(a) strrchr(s, c);
(b) strfchr(s, c);
(c) strchr(s, c);
(d) strlchr(s, c);
124. What is the output of this C code?
#include <stdio.h>
int main()
{
int x = 2, y = 0;
int z = y && (y |= 10);
printf("%d\n", z);
return 0;
}
_________
Ans: 0
125. What is the output of this C code?
#include <stdio.h>
int main()
{
int x = 2, y = 0;
int z = (y++) ? 2 : y == 1 && x;
printf("%d\n", z);
return 0;
}
_________
Ans: 1
126. What is the output of this C code?
#include <stdio.h>
int main()
{
int x = 2, y = 0, l;
int z;
z = y = 1, l = x && y;
printf("%d\n", l);
return 0;
}
_________
Ans: 1
127. What is the output of this C code?
#include <stdio.h>
int main()
{
int y = 2;
int z = y +(y = 10);
printf("%d\n", z);
}
_________
Ans: 20
128. What is the output of this C code?
#include <stdio.h>
int main()
{
int x = 3, y = 2;
int z = x << 1 > 5;
printf("%d\n", z);
}
________
Ans: 1
129. The code snippet below produces
#include <stdio.h>
void main()
{
1 < 2 ? return 1 : return 2;
}
(a) Compile time error
(b) returns 1
(c) Varies
(d) returns 2
130. What is the output of this C code?
#include <stdio.h>
struct
{
int k;
char c;
} p;
int p = 10;
int main()
{
p.k = 10;
printf("%d %d\n", p.k, p);
}
(a) Compile time error
(b) 10 10
(c) Depends on the compiler
(d) Depends on the standard
131. What is the output of the below code considering size of short int is 2, char is 1 and int is 4 bytes?
#include <stdio.h>
int main()
{
short int i = 20;
char c = 97;
printf("%d, %d, %d\n", sizeof(i), sizeof(c), sizeof(c + i));
return 0;
}
(a) 2, 1, 4
(b) 2, 1, 1
(c) 2, 2, 8
(d) 2, 1, 2
132. What is the output of this C code?
#include <stdio.h>
int main()
{
int i = 10;
int *p = &i;
printf("%d\n", *p++);
}
(a) 10
(b) Garbage value
(c) Address of i
(d) 11
133. What is the return-type of the function sqrt()
(a) int
(b) double
(c) Depends on the data type of the parameter
(d) float
134. What is the output of this C code?
#include <stdio.h>
int main()
{
int x = 2, y = 2;
int z = x ^ y & 1;
printf("%d\n", z);
}
_________
Ans: 2
135. What is the output of the code given below?
#include <stdio.h>
int main()
{
printf("%d ", 1);
goto l1;
printf("%d ", 2);
l1:goto l2;
printf("%d ", 3);
l2:printf("%d ", 4);
}
_________
Ans: 1 4
136. The output of the code below is
#include <stdio.h>
int *m()
{
int *p = 5;
return p;
}
void main()
{
int *k = m();
printf("%d", k);
}
_________
Ans: 5
137. What will be the size of the following structure?
#include <stdio.h>
struct temp
{
int a[10];
char p;
};
_________
Ans: 44
138. The preprocessor provides the ability for _______________.
(a) All of the mentioned
(b) The inclusion of header files
(c) Conditional compilation and line control.
(d) The inclusion of macro expansions
139. Which is true about isalnum(c), where c is an int that can be represented as an unsigned char or EOF.isalnum(c)
returns?
(a) 0 if not isalpha(c) or not isdigit(c)
(b) Non-zero if isalpha(c) or isdigit(c)
(c) Both Non-zero if isalpha(c) or isdigit(c) & 0 if not isalpha(c) or not isdigit(c)
(d) None of the mentioned
140. What is the output of this C code?
#include <stdio.h>
int main()
{
foo(ary);
}
void foo(int **ary)
{
int i = 10, k = 10, j = 2;
int *ary[2];
ary[0] = &i;
ary[1] = &j;
printf("%d\n", ary[0][1]);
}
(a) 10
(b) 2
(c) Undefined behaviour
(d) Compile time error
141. The #include directive
(a) Tells the preprocessor to grab the text of a file and place it directly into the current file
(b) Statements are typically placed at the top of a program
(c) Both a & b
(d) None of these
142. What is the output of this C code?
#include <stdio.h>
struct p
{
struct p *next;
int x;
};
int main()
{
struct p *p1 = calloc(1, sizeof(struct p));
p1->x = 1;
p1->next = calloc(1, sizeof(struct p));
printf("%d\n", p1->next->x);
return 0;
}
_______
Ans: 0
143. What is the output of this C code?
#include <stdio.h>
#include <math.h>
void main()
{
int k = pow(2, 3);
printf("%d\n", k);
}
_________
Ans: 8
144. What is the output of this C code?
#include <stdio.h>
#include <math.h>
void main()
{
int k = fabs(-87);
printf("%d\n", k);
}
______
Ans: 87
145. The number of digits present after decimal in float is ?
Ans: 6
146. What is the output of this C code?
#include <stdio.h>
int main()
{
char *str = "hello, world\n";
printf("%d", strlen(str));
}
_________
Ans: 13

You might also like