1. Which of the following statements will result in a compilation error?

Answers:

  1. int n=5, x; x=n++;
  2. int n=5, x; x= ++n++;
  3. int n=5, x; x= (n+1)++;
  4. int n=5, x=6; x= (n+x)++;
  5. None of the above

2. Read the following two declaration statements.

1. #include <stdio.h>
2. #include “stdio.h”

Which of the following statements pertaining to the above two statements are correct?

Answers:

  1. For statement 1, the header file will be searched first in the local directory and then in the standard system directories such as “/usr/include”
  2. For statement 1, the header file will be searched in the standard system directories such as “/usr/include”
  3. For statement 2, the header file will be searched first in the local directory and then in the standard system directories such as “/usr/include”
  4. For statement 2, the header file will be searched in the standard system directories such as “/usr/include”
  5. None of the above

3. Which of the following statements are correct for the keyword register?

Answers:

  1. It is a storage-class-specifier
  2. It guarantees that the variable is kept in the CPU register for maximum speed
  3. It requests that the variable be kept in the CPU register for maximum speed
  4. It does not guarantee that the variable value is kept in CPU register for maximum speed

4. Which is/are the type/s of memory allocation that needs/need the programmer to take care of memory management?

Answers:

  1. Static memory allocation
  2. Dynamic memory allocation
  3. Automatic memory allocation
  4. Memory allocation on stack
  5. Memory allocation on heap

5. Which of the following comparison statements will be true if an integer is 16 bits and a long is 32 bits on a machine?

Answers:

  1. -1L < 1U
  2. -1L > 1U
  3. -1L < 1UL
  4. -1L > 1UL

6. Which of the following is the correct way of initializing a two-dimensional array?

Answers:

  1. char str[2][4]={ “abc”, “def” };
  2. char str[2][4]={ {“abc”}, {“def”} };
  3. char str[2][4]={ {‘a’,’b’,’c’,”}, {‘d’,’e’,’f’,”} };
  4. a and b
  5. a, b and c

7. Given the array:
int num[3][4]= {
{3,6,9,12},
{15,25,30,35},
{66,77,88,99}
};
what would be the output of *(*(num+1)+1)+1?

Answers:

  1. 3
  2. 15
  3. 26
  4. 66
  5. 77

8. Which function will you use to write a formatted output to the file?

Answers:

  1. fputc()
  2. fputs()
  3. fprintf()
  4. fseek()
  5. ftell()

9. Given the array:
int num[3][4]=
{
{3,6,9,12},
{15,25,30,35},
{66,77,88,99}
};

what would be the output of *(*(num+1))?

Answers:

  1. 3
  2. 15
  3. 66
  4. 6
  5. 25

10. What would be printed on the standard output as a result of the following code snippet?

main()
{
char option = 5;
switch(option)
{
case ‘5’:
printf(“case : 1 n”);
break;
case 5:
printf(“case : 2 n”);
break;
default:
printf(“case : 3 n”);
break;
}
return 0;
}

Answers:

  1. case : 1
  2. case : 2
  3. case : 3
  4. Result in compilation error
  5. None of the above

11. What would be printed on the standard output as a result of the following code snippet?

main()
{
int i=5;
char option = 5;
switch(option)
{
case ‘5’:
printf(“case : 1 n”);
break;
case i:
printf(“case : 2 n”);
break;
default:
printf(“case : 3 n”);
break;
}
return 0;
}

Answers:

  1. case : 1
  2. case : 2
  3. case : 3
  4. Result in compilation error
  5. None of the above

12. What would be printed on the standard output as a result of the following code snippet?

#define func(t, a, b) { t temp; temp=a; a=b; b=temp; }
main()
{
int a=3, b=4;
float c=4.5, d = 5.99;
func(int, a, b);
func(float, c, d);
printf(“%d %d “, a, b);
printf(“%.2f %.2fn”, c, d);
}

Answers:

  1. Results in Compilation Error
  2. 3 4 5.99 4.50
  3. 3 4 4.50 5.99
  4. 4 3 5.99 4.50
  5. None of the above

13. What would be printed on the standard output as a result of the following code snippet?

main()
{
void addup (int b);
addup(b);
return 0;
}
int b = 5;
void addup (int b)
{
static int v1;
v1 = v1+b;
printf(“%d “, v1);

}

Answers:

  1. Will result in Compilation Error
  2. 5
  3. 0
  4. Undefined value

14. Given the following array declaration:

int a[2][3][4];
what would be the number of elements in array a?

Answers:

  1. 24
  2. 22
  3. 20
  4. 12
  5. 36

15. Which file header is to be included for file handling in a C program?

Answers:

  1. string.h
  2. file.h
  3. stdio.h
  4. stdlib.h
  5. ctype.h

16. What is the return type of the following function declaration?
func(char c);

Answers:

  1. void
  2. char
  3. int
  4. undefined

17. What is the return value in case a file is not opened successfully by using fopen()?

Answers:

  1. 0
  2. 1
  3. 100
  4. NULL

18. What is the function to concatenate two strings?

Answers:

  1. strcmp()
  2. strcpy()
  3. strcat()
  4. strlen()
  5. catstr()

19. Which of the following statements is valid and correct?

Answers:

  1. char amessage[] = “lmnop”; amessage++;
  2. char *pmessage = “abcde”; (*pmessage)++;
  3. char amessage[] = “lmnop”; (*amessage)++;
  4. char *pmessage = “abcde”; pmessage++;

20. What will be the output of following code?

int main()
{
int i;
i = 0;
for (i = 1; i <2; i++)
{
i++;
printf( “%d”, i );
continue;
printf( “%d”, i );
}
return 0;
}

Answers:

  1. 22
  2. 2,2
  3. 2
  4. none of the above

21. Which of the following is not a valid mode for opening a file?

Answers:

  1. r
  2. w
  3. a
  4. r+
  5. i

22. Given the following array:

char books[][40]={
“The Little World of Don Camillo”,
“To Kill a Mockingbird”,
“My Family and Other Animals”,
“Birds, Beasts and Relatives”
};
what would be the output of printf(“%c”,books[2][5]);?

Answers:

  1. m
  2. M
  3. F
  4. i
  5. L

23. What would be printed on the standard output as a result of the following code snippet?

char *str1 = “Hello World”;
strcat(str1, ‘!’);
printf(“%s”, str1);

Answers:

  1. Hello World!
  2. Hello World
  3. Hello
  4. The code snippet will throw a compilation error

24. What will be printed on the standard output as a result of the following code snippet?

void main()
{
char arr[] = {‘R’,’A’,’M’,”};
printf(“%d”,strlen(arr));
}

Answers:

  1. 0
  2. 1
  3. 3
  4. 4
  5. Cannot be determined

25. Given the following array:

int a[8] = {1,2,3,4,5,6,7,0};
what would be the output of
printf(“%d”,a[4]); ?

Answers:

  1. 3
  2. 4
  3. 5
  4. 6
  5. 7

26. In order to read structures/records from a file, which function will you use?

Answers:

  1. fscanf()
  2. fread()
  3. fgets()
  4. fgetc()
  5. fseek

27. An array is defined with the following statement in a file, file1.c

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

In another file, file2.c, the following code snippet is written to use the array a:

extern int a[];
int size = sizeof(a);

What is wrong with the above code snippet?

Answers:

  1. The size of the operator cannot be applied to an array
  2. There is nothing wrong with the code snippet. The value of the size will be 6
  3. There is nothing wrong with the code snippet. The value of the size will be 7
  4. An extern array of unspecified size is an incomplete type. The size of the operator during compile time is unable to learn the size of an array that is defined in another file
  5. None of the above

28. What would be printed on the standard output as a result of the following code snippet?

main()
{
char *s=”Hello World”;
char s1[20], s2[20];
int len = sscanf(s,”%s”,s1);
printf(“%s : %d”, s1, len);
}

Answers:

  1. Compilation Error
  2. Hello World : 11
  3. Hello World : 1
  4. Hello : 5
  5. Hello : 1

29. Suppose there is a file a.dat which has to be opened in the read mode using the FILE pointer ptr1, what will be the correct syntax?

Answers:

  1. ptr1 = open(“a.dat”);
  2. ptr1 = fileopen(“a.dat”);
  3. ptr1 = fopen(“a.dat”,”r”);
  4. ptr1 = open(“a.dat”,”r”);
  5. ptr1 = fileopen(“a.dat”,”r”);

30. Given the following array:

char books[][40]={
“The Little World of Don Camillo”,
“To Kill a Mockingbird”,
“My Family and Other Animals”,
“Birds, Beasts and Relatives”
};
what would be the output of printf(“%s”,books[3]);?

Answers:

  1. Birds
  2. B
  3. Birds, Beasts and Relatives
  4. My Family and Other Animals
  5. M

31. What would be printed on the standard output as a result of the following code snippet?

void main()
{
unsigned char a=25;
a = ~a;
signed char b = 25;
b = ~b;
printf(“%d %d “, a, b);
}

Answers:

  1. 0 0
  2. 230 230
  3. 230 -26
  4. 230 -103
  5. None of the above

32. Which function will convert a string into a double precision quantity?

Answers:

  1. atoi()
  2. atof()
  3. atol()
  4. atan()
  5. acos()

33. Which of the following is not a type of operator ?

Answers:

  1. Rational
  2. Unary
  3. Ternary
  4. Compound assignment
  5. Logical

34. The declaration int *(*p)[10] indicates:

Answers:

  1. p is an array of pointers to functions the return type of which is an integer
  2. p is a pointer to a function that returns a pointer to an integer
  3. p is a pointer to an array of integer pointers
  4. p is a pointer to a character string

35. What will be printed on the standard output as a result of the following code snippet?

void main()
{
int num1 = 30, num2 = 4;
float result;
result = (float)(num1/num2);
printf(“%.2f”, result);
return 0;
}

Answers:

  1. 7
  2. 7.00
  3. 7.000000
  4. 7.5
  5. 7.50

36. What is the output of the following program ?

main()
{

int u = 1, v = 3;
printf(“%d %d”,u,v);
funct1(&u,&v);
printf(” %d %dn”,u,v);
}

void funct1(int *pu, int *pv)
{
*pu=0;
*pv=0;
return;
}

Answers:

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

37. Which of the following is/are the correct signature/s of main with command line arguments?

Answers:

  1. int main(int argc, char **argv)
  2. int main(int argc, char *argv[])
  3. int main(int argc, char *argv)
  4. int main(int argc, char argv[])
  5. All of the above

38. From which of the following loop or conditional constructs, is “break” used for an early exit?

Answers:

  1. switch
  2. for
  3. while
  4. do-while
  5. All of the above

39. Given the operators:

1) *
2) /
3) %

What would be the order of precedence?

Answers:

  1. 1,2,3
  2. 1,3,2
  3. 3,2,1
  4. All have the same precedence
  5. 1 and 2 have the same precedence, 3 is of lower precedence

40. Which of the following declarations of structures is/are valid?

1)
struct node {
int count;
char *word;
struct node next;
}Node;
2)
struct node {
int count;
char *word;
struct node *next;
}Node;
3)
struct node {
int count;
char *word;
union u1 {
int n1;
float f1;
}U;

}Node;

Answers:

  1. 1,2,3
  2. 1,2
  3. 2,3
  4. 2
  5. None of the above

41. What would be printed on the standard output as a result of the following code snippet?

main( )
{
char *str[ ] = {
“Manish”
“Kumar”
“Choudhary”
};
printf ( “nstring1 = %s”, str[0] );
printf ( “nstring2 = %s”, str[1] );
printf ( “nstring3 = %s”, str[2] );
}

Answers:

  1. string1 = Manish string2 = Kumar string3 = Choudhary
  2. string1 = Manish string2 = Manish string3 = Manish
  3. string1 = ManishKumarChoudhary string2 = (null) string3 = (null)
  4. You will get an error message from the compiler

42. What would be printed on the standard output as a result of the following code snippet?

main()
{
int n=5, x;
x = n++;
printf(“%d “, x);
x = ++n;
printf(“%d “, x++);
printf(“%d”, x);
return 0;
}

Answers:

  1. 6 7 8
  2. 5 7 8
  3. 6 8 8
  4. 5 8 8
  5. None of the above

43. In which area of memory are static variables allocated?

Answers:

  1. stack
  2. heap
  3. With the code binary
  4. None of the above

44. Which standard function is used to deallocate memory allocated by the malloc() function?

Answers:

  1. free
  2. calloc
  3. delete
  4. release
  5. destroy

45. Read the statement below:

extern int a;

Which of the following statement/s pertaining to the above statement is/are correct?

Answers:

  1. Declares an integer variable a; Allocates storage for the variable
  2. Declares an integer variable a; Does not allocate the storage for the variable
  3. Indicates that the variable is defined outside the current file
  4. Brings the scope of the variable defined outside the file to this file
  5. All of the above
  6. None of the above

46. The declaration int (*p[5])() means:

Answers:

  1. p is an array of pointers to functions the return type of which is an integer
  2. p is a pointer to a function that returns a pointer to an integer
  3. p is a pointer to an array of integers
  4. p is a pointer to an array of integer pointers
  5. p is a pointer to a character string

47. What will be printed on the standard output as a result of the following code snippet?

void main()
{
int arr[5]={1,2,3,4,5};
printf(“%dn”, *(arr+4));
}

Answers:

  1. 1
  2. 2
  3. 4
  4. 5
  5. Cannot be determined

48. What would be printed on the standard output as a result of the following code snippet?

main()
{
char *pmessage = “asdfgh”;
*pmessage++;
printf(“%s”, pmessage);
return 0;
}

Answers:

  1. Will result in Compilation Error
  2. Undefined string
  3. sdfgh
  4. asdfgh

49. Which function returns the current pointer position within a file?

Answers:

  1. ftell()
  2. fseek()
  3. fgetc()
  4. fread()
  5. fscanf()

50. Which of the following is not a relational operator?

Answers:

  1. ==
  2. !=
  3. <>
  4. >=
  5. <=

51. What does the argv[0] represent?

Answers:

  1. The first command line parameter has been passed to the program
  2. The program name
  3. The number of command line arguments
  4. None of the above

52. What will happen when the following code is executed?

void main()
{
char arr1[] = “REGALINT”;
char arr2[10] = “REGALINT”;
printf(“%d,”,sizeof(arr1));
printf(“%d”,sizeof(arr2));
}

Answers:

  1. 1,1
  2. 1,4
  3. 8,8
  4. 8,9
  5. 9,10

53. What will be the output of the following program?

#include <assert.h>
main()
{
int n = 5;
assert(n > 3); //statement 1
n = n+2;
assert(n > 7);//statement 2
return 0;
}

Answers:

  1. Assertion ‘n > 3’ failed; Program aborts at statement 1
  2. Assertion ‘n > 7’ failed; Program aborts at statement 2
  3. Program returns 0 with the value of n as 7
  4. Compilation Error

54. Which of the following is a function for formatting data in memory?

Answers:

  1. sprintf()
  2. printf()
  3. scanf()
  4. free()
  5. atol()

55. Which function allocates memory and initializes elements to 0?

Answers:

  1. assign()
  2. calloc()
  3. malloc()
  4. swab()
  5. allocate()

56. Is the following statement correct? If not, why not? If yes, what is the size of the array?

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

Answers:

  1. Yes, the size is three columns by two rows
  2. Yes, the size is two columns by two rows
  3. No, the first dimension is omitted
  4. No, one of the three initializer sets contains too many numbers
  5. Yes, the size is three columns by three rows

57. Which of the following sets of conversion statements may result in the loss of data?

Answers:

  1. int i; char c; i=c; c=i;
  2. int i; char c; c=i; i=c;
  3. int i; float f; i=f; f=i;
  4. None of the above

58. Consider the following code.

int i = 4, *j, *k;

Which one of the following statements will result in Compilation error?

Answers:

  1. j = &i;
  2. j = j + 4;
  3. j = j – 2;
  4. k = j + 3;
  5. j = j * 2;

59. What would be printed on the standard output as a result of the following code snippet?

main()
{
enum {red, green, blue = 0, white};
printf(“%d %d %d %d”, red, green, blue, white);
return 0;
}

Answers:

  1. Will result in Compilation Error
  2. 0 1 2 3
  3. 0 1 0 1
  4. 0 1 0 2
  5. Undefined

60. By which file function you can position the file pointer in accordance with the current position?

Answers:

  1. ftell()
  2. fseek()
  3. fgetc()
  4. fread()
  5. fscanf()

61. What is wrong with the following function prototype statement?

int func();

Answers:

  1. The function definition {…} is missing
  2. While calling a function, the type int is not needed
  3. No parameter has been passed
  4. The semicolon should not be there
  5. There is nothing wrong with the statement

62. What will be printed on the standard output as a result of the following code snippet?

void main()
{
char arr[] = {‘R’,’A’,’M’};
printf(“%d”,strlen(arr));
}

Answers:

  1. 0
  2. 1
  3. 3
  4. 4
  5. Cannot be determined

63. What will be printed on the standard output as a result of the following code snippet?

void main()
{
int arr[][2] = {1,2,3,4,5,6};
printf(“%d”,arr[2][1]);
}

Answers:

  1. 2
  2. 3
  3. 4
  4. 5
  5. 6

64. What would be printed on the standard output as a result of the following code snippet?

#include<stdio.h>
main()
{
unsigned char a=255;
a = a+1;
printf(“%d”,a);
return 0;
}

Answers:

  1. Undefined value
  2. 256
  3. 1
  4. 0
  5. -1

65. Which of the following is not a storage type?

Answers:

  1. auto
  2. global
  3. static
  4. register
  5. extern

66. If a two dimensional array arr[4][10](an array with 4 rows and 10 columns) is to be passed in a function, which of the following would be the valid parameters in the function definition?

Answers:

  1. fn(int arr[4][10])
  2. fn(int arr[][10])
  3. fn(int arr[4][])
  4. fn(int (*fn)[13])
  5. None of the above

67. Which function will you use to position the file pointer at the beginning of the file?

Answers:

  1. rewind()
  2. fseek()
  3. fscanf()
  4. a or b
  5. b or c

68. Which of the following is not a string function?

Answers:

  1. strlen()
  2. strcmp()
  3. strcpy()
  4. strcomp()

69. What would be printed on the standard output as a result of the following code snippet?

char i = ‘A’;
char *j;
j = & i;
*j = *j + 32;
printf(“%c”,i);

Answers:

  1. An error will occur
  2. a
  3. A
  4. b
  5. c

70. What will be printed on the standard output as a result of the following code snippet?

void main()
{
char arr1[] = “REGALINT”;
printf(“%d,”,strlen(arr1));
printf(“%d”,sizeof(arr1));
}

Answers:

  1. 1,1
  2. 8,4
  3. 8,8
  4. 8,9
  5. 9,8

71. What will be printed on the standard output as a result of the following code snippet?

int funr(int x, int y)
{
if(x <= 0)
{
return y;
}
else
{
return (1+funr(x-1,y));
}
}

void main()
{
printf(“%d”,funr(2,3));
}

Answers:

  1. 2
  2. 3
  3. 5
  4. 6
  5. 9

72. Which header file are methods(or macros) isalpha(), islower() a part of?

Answers:

  1. stdio.h
  2. ctype.h
  3. string.h
  4. math.h
  5. None of the above

73. What would be printed on the standard output as a result of the following code snippet?

#define Name Manish
main()
{
printf(“My name””Name”);
}

Answers:

  1. My name Manish
  2. My nameName
  3. Results in Compilation Error
  4. None of the above

74. What will be printed on the standard output as a result of the following code snippet?

void main()
{
int i,j,k;
i=4;
j=30;
k=0;
k=j++/i++;
++k;
printf(“%d %d %d”,i,j,k);
}

Answers:

  1. 5 31 8
  2. 5 31 7
  3. 5 31 6
  4. 4 30 7

75. What will be printed on the standard output as a result of the following code snippet?

main()
{
int num = 425;
printf(“%d”, printf(“%d”, num));
}

Answers:

  1. Will result in Compilation Error
  2. 4425
  3. 4253
  4. 3435
  5. None of the above

76. What would be printed on the standard output as a result of the following code snippet?

main()

{

signed char i = 1;

for (; i<=255; i++)

printf (“%d “,i);

return 0;

}

Answers:

  1. Compilation Error
  2. 1 2 3 … 255
  3. 1 2 3 . . . 127
  4. 1 2 3 . . . 127 -128 -127 … 0 1 2 3 . . . (infinite times)

77. What would be printed on the standard output as a result of the following code snippet?

#define max(a, b) ((a) > (b)?(a):(b))
main()
{
int a=4;
float b=4.5;
printf(“%.2fn”,max(a, b));
}

Answers:

  1. Results in Compilation Error
  2. Undefined value
  3. 4.50
  4. 4.0
  5. None of the above

78. Which of the following is not a file related function?

Answers:

  1. fgetc()
  2. puts()
  3. fputc()
  4. fscanf()
  5. fprintf()

79. What would be printed on the standard output as a result of the following code snippet?

main()
{
enum {red, green, blue = 6, white};
printf(“%d %d %d %d”, red, green, blue, white);
return 0;
}

Answers:

  1. 0 1 6 2
  2. 0 1 6 7
  3. Will result in Compilation Error
  4. None of the above

80. What would be printed on the standard output as a result of the following code snippet?

main()
{
int a[5] = {1,4,5,6,9};
printf(“%dt”, *a); //Line 1
printf(“%d”, *++a); //Line 2
return 0;
}

Answers:

  1. 1 4
  2. 0 1
  3. Undefined value
  4. Compilation Error in “Line 1”
  5. Compilation Error in “Line 2”

81. What would be printed on the standard output as a result of the following code snippet?

#define max(a, b)((a) > (b)?(a):(b))
main()
{
int a=4, c = 5;
printf(“%d “, max(a++, c++));
printf(“%d %dn”, a,c);
}

Answers:

  1. Results in Compilation Error
  2. 6 4 5
  3. 6 5 7
  4. 6 5 6
  5. None of the above

82. Which of the following file modes would mean read + append?

Answers:

  1. w+
  2. a+
  3. r+
  4. r+a
  5. a+r

83. Which of the following standard functions is used to close a file?

Answers:

  1. fileclose()
  2. closefile()
  3. fclose()
  4. Any of the above

84. What would be printed on the standard output as a result of the following code snippet?

int Recur(int num)
{
if(num==1 || num==0)
return 1;
if(num%2==0)
return Recur(num/2)+2;
else
return Recur(num-1)+3;
}

int main()
{
int a=9;
printf(“%dn”, Recur(a));
return 0;
}

Answers:

  1. 10
  2. 9
  3. 11
  4. 8
  5. None of the above

85. Identify the incorrect statement.

Answers:

  1. Records can be defined in C by using structures
  2. Structure members can be of the same/different data types
  3. Memory is reserved when a structure label is defined
  4. A pointer to a structure can be used to pass a structure to a function
  5. Arrays of structures can be defined and initialized

86. What will happen when the following code is executed?

{
int num;
num =0;
do {– num;
printf(“%dn”, num);
num++;
} while (num >=0);
}

Answers:

  1. The loop will run infinitely
  2. The program will not enter the loop
  3. There will be a compilation error
  4. A runtime error will be reported

87. Which of the following functions is used to extract formatted input from a file?

Answers:

  1. fputc()
  2. fputs()
  3. fprintf()
  4. fscanf()
  5. ftell()

88. What does the following function do?

int fn(unsigned int x)
{
int count = 0;
for(; x!=0; x&=(x-1))
count++;
return count;
}

Answers:

  1. Returns the minimum number of bits required to represent the number x
  2. Returns the number of zero bits present in the number x
  3. Returns the number of 1 bits(bits having one) in the number x
  4. Returns the square root of the number
  5. None of the above

1,514 total views, 4 views today