Vous êtes sur la page 1sur 8

Dr. Mahalingam College of Engineering & Technology, Pollachi.

C-Programming - Test

Q1. void main() { int a=10,b=20; char x=1,y=0; if(a,b,x,y) { printf("EXAM"); } } What is the output? 1) XAM is printed 2) exam is printed 3) Compiler Error 4) Nothing is printed Q2. Array passed as an argument to a function is interpreted as 1) Address of the array 2) Values of the first elements of the array 3) Address of the first element of the array 4) Number of element of the array Q3. #include <stdio.h> void main() { int I=3,*j,**k; j=&I; k=&j; printf("%d%d%d",*j,**k,*(*k)); } What is the output of the above program code? 1) 444 2) 000 3) 333 4) 433

Q4. Which of the following is the feature of stack? 1) All operations are at one end 2) It cannot reuse its memory 3) All elements are of different data types 4) Any element can be accessed from it directly

Q5. fputs function is used to i. write characters to a file ii. takes 2 parameters iii. returns a character iv. requires a file pointer 1) all are true 2) all are false 3) only i and ii are true 4) only i,ii and iv are true

Q6. To delete a dynamically allocated array named `a`, the correct statement is 1) delete a; 2) delete a[0]; 3) delete []a; 4) delete [0]a;

Q7. What will be the value of `a` after the following code is executed #define square(x) x*x a = square(2+3) 1) 25 2) 13 3) 11 4) 10

Q8. main() { static int var = 5; printf("%d ",var--); if(var) main(); } What is the output of above program? 1) 5 5 5 5 5 2) 5 4 3 2 1 3) 4 3 2 1 4) None of these options Q9. The size of a structure can be determined by a. size of variable name b. size of (struct tag) 1) Only a 2) Only b 3) Both a and b 4) None of these options

Q10. Is there any difference between the two declarations, YES/NO 1. int foo(int *arr[]) and 2. int foo(int *arr[2])

Q11 Which header file should be included to use functions like malloc() and calloc()? 1) memory.h 2) stdlib.h 3) string.h 4) dos.h Q12 What function should be used to free the memory allocated by calloc() ?

1) 2) 3) 4)
Q13

dealloc(); malloc(variable_name, 0) free(); memalloc(variable_name, 0)

What does the following declaration mean? int (*ptr)[10]; 1) 2) 3) 4) Q14 What is (void*)0? 1) 2) 3) 4) Representation of NULL pointer Representation of void pointer Error None of above ptr is array of pointers to 10 integers ptr is a pointer to an array of 10 integers ptr is an array of 10 integers ptr is an pointer to array

Q15 Point out the error in the program #include<stdio.h> int main() { int a[] = {10, 20, 30, 40, 50}; int j; for(j=0; j<5; j++) { printf("%d\n", a); a++; } return 0; } 1) Error: Declaration syntax 2) Error: Expression syntax 3) Error: LValue required 4) Error: Rvalue required Q16 What will be the output of the program in 16 bit platform (Turbo C under DOS)? #include<stdio.h> int main() { int fun(); int i; i = fun(); printf("%d\n", i); return 0; } int fun() { _AX = 1990; } 1) Garbage value

2) 0 (Zero) 3) 1990 4) No output Q17 Point out the error in the program #include<stdio.h> int f(int a) { a > 20? return(10): return(20); } int main() { int f(int); int b; b = f(20); printf("%d\n", b); return 0; } 1) Error: Prototype declaration 2) No error 3) Error: return statement cannot be used with conditional operators 4) None of above Q18 Which of the following statements are correct about the program? #include<stdio.h> int main() { printf("%p\n", main()); return 0; } 1) It prints garbage values infinitely 2) Runs infinitely without printing anything 3) Error: main() cannot be called inside printf() 4) No Error and print nothing Q19 Which of the following statements are correct about the function? long fun(int num) { int i; long f=1; for(i=1; i<=num; i++) f = f * i; return f; } 1) The function calculates the value of 1 raised to power num.

2) The function calculates the square root of an integer 3) The function calculates the factorial value of an integer 4) None of above Q20 Which of the following statements should be used to obtain a remainder after dividing 3.14 by 2.1 ? 1) 2) 3) 4) Q21 What will be the output of the program ? #include<stdio.h> int main() { union a { int i; char ch[2]; }; union a u; u.ch[0]=3; u.ch[1]=2; printf("%d, %d, %d\n", u.ch[0], u.ch[1], u.i); return 0; } 1) 3, 2, 515 2) 515, 2, 3 3) 3, 2, 5 4) 515, 515, 4 Q22 What will the SWAP macro in the following program be expanded to on preprocessing? will the code compile? #include<stdio.h> #define SWAP(a, b, c)(c t; t=a, a=b, b=t) int main() { int x=10, y=20; SWAP(x, y, int); printf("%d %d\n", x, y); return 0; } 1) It compiles 2) Compiles with an warning rem = 3.14 % 2.1; rem = modf(3.14, 2.1); rem = fmod(3.14, 2.1); Remainder cannot be obtain in floating point division.

3) Not compile 4) Compiles and print nothing Q23 What will be the output of the program ? #include<stdio.h> int main() { printf(5+"Good Morning\n"); return 0; } 1) Good Morning 2) Good 3) M 4) Morning Q24 Which of the following statements are correct about the below declarations? char *p = "Sanjay"; char a[] = "Sanjay"; 1:There is no difference in the declarations and both serve the same purpose. 2:p is a non-const pointer pointing to a non-const string, whereas a is a const pointer pointing to a non-const pointer. 3:The pointer p can be modified to point to another string, whereas the individual characters within array a can be changed. 4:In both cases the '\0' will be added at the end of the string "Sanjay". 1) 2) 3) 4) 1, 2 2, 3, 4 3, 4 2, 3

Q25 What will be the output of the program? #include<stdio.h> #include<stdlib.h> union employee { char name[15]; int age; float salary; }; const union employee e1; int main() { strcpy(e1.name, "K"); printf("%s %d %f", e1.name, e1.age, e1.salary);

return 0; } 1) 2) 3) 4) Error: RValue required Error: cannot convert from 'const int *' to 'int *const' Error: LValue required in strcpy No error

Vous aimerez peut-être aussi