c test

6
C PROGRAMMING –APTITUDE TEST 1 ROLL NO: TIME: 20 MINUTES 1.Is there any difference between following declarations? 1 : extern int fun(); 2 : int fun(); A . Both are identical B . No difference, except extern int fun(); is probably in another file C . int fun(); is overrided with extern int fun(); D . None of these 2. By default a real number is treated as a A . float B . double C . long double D . far double 3 . Is the following statement a declaration or definition? extern int i; A . Declaration B . Definition C . Function D . Error 4. What will you do to treat the constant 3.14 as a long double? A . use 3.14LD B . use 3.14L C . use 3.14DL D . use 3.14LF

Upload: chikkusridhar

Post on 07-Dec-2015

213 views

Category:

Documents


1 download

DESCRIPTION

C

TRANSCRIPT

Page 1: C test

C PROGRAMMING –APTITUDE TEST 1 ROLL NO:

TIME: 20 MINUTES

1.Is there any difference between following declarations?

1 : extern int fun();2 : int fun();A.

Both are identical

B.No difference, except extern int fun(); is probably in another fileC.int fun(); is overrided with extern int fun();D.

None of these

2. By default a real number is treated as aA.

float B.double

C.long double D.far double

3. Is the following statement a declaration or definition?extern int i;A.Declaration B.DefinitionC.Function D.Error

4. What will you do to treat the constant 3.14 as a long double?A.use 3.14LD B.use 3.14LC.use 3.14DL D.use 3.14LF

5. We want to round off x, a float, to an int value, The correct way to do isA.y = (int)(x + 0.5) B.y = int(x + 0.5)C.y = (int)x + 0.5 D.y = (int)((int)x + 0.5)

FIND THE OUTPUT OF THE FOLLOWING CODE SNIPPETS

6. int main(){ float a=0.7; if(a < 0.7) printf("C\n"); else printf("C++\n"); return 0;}

Page 2: C test

A.

C B.C++

C.Compiler error D.Non of above7. #include<stdio.h>#include<math.h>int main(){ printf("%f\n", sqrt(36.0)); return 0;}

A.

6.0 B.6

C.6.000000 D.Error: Prototype sqrt() not found.

8. int main(){ int x = 10, y = 20, z = 5, i; i = x < y < z; printf("%d\n", i); return 0;}

A.

0 B.1

C.Error D.None of these

9.

1. What is the correct value to return to the operating system upon the successful completion of a program?A. -1 B. 1 C. 0 D. Programs do not return a value.

10.

int main(){ void v = 0;

printf("%d", v);

return 0;}

A.

Error: Declaration syntax error 'v' (or) Size of v is unknown or zero.

B.Program terminates abnormally.

Page 3: C test

C.No error.D.

None of these.

11.

 Which of the following special symbol allowed in a variable name?A.

* (asterisk) B.| (pipeline)

C.- (hyphen) D._ (underscore)

12. Which header file should be included to use functions like malloc() and calloc()?A.

memory.h B.stdlib.h

C.string.h D.dos.h

13. #include <stdio.h>

int main(void){ int i = 3; int j;

j = sizeof(++i + ++i);

printf("i=%d j=%d\n", i, j);

return 0;}

A.

I=4 j=2 B. i=3 j=2

C. i=5 j=2 D. Undefined behaviour

14. #include<stdio.h>

int main(){ int y=128; const int x=y; printf("%d\n", x); return 0;}

A.

128 B.Garbage value

C.Error D.0

15.

Page 4: C test

int main(){ extern int a; printf("%d\n", a); return 0;}int a=20;

A.

20 B.0

C.Garbage Value D.Error

16. int main(){ int X=40; { int X=20; printf("%d ", X); } printf("%d\n", X); return 0;}

A.

extern int a is declaration, int a = 20 is the definition

B.int a = 20 is declaration, extern int a is the definitionC.int a = 20 is definition, a is not definedD.

a is declared, a is not defined

17. Write the output(if any) of the given program (2 marks). If error, mention the error & reason.

void abc()

{

auto int b=0;

Static int s;

s=0;

++s;

++b;

printf(“%d %d \n “, b, s);

}

void main()

{

Page 5: C test

abc(); abc(); abc();

}

18. Write a program to swap two numbers without using a temporary variable. (2 marks)