Vous êtes sur la page 1sur 8

1/23/2015

1/23/2015 00:19:45 Like Share  

00:19:45

1/23/2015 00:19:45 Like Share  
Like Share

Like Share

 

1/23/2015 00:19:45 Like Share  

C Programming Test ‐ Random

C Programming
C Programming
Result & Statistics
Result & Statistics
C Programming Result & Statistics } int fun(int a, int b) { B. None of above
} int fun(int a, int b) { B. None of above P is character type P
}
int fun(int a, int b)
{
B.
None of above
P is character type
P is a constant
In the following code what is 'P'?
typedef char *charp;
const charp P;
Answer: Option A
Learn more problems on : Typedef
Discuss about this problem : Discuss in Forum
What will be the output of the program?
#include<stdio.h>
int fun(int, int);
typedef int (*pf) (int, int);
int proc(pf, int, int);
printf("%d\n", proc(fun, 6, 6));
return 0;
P is a character constant
return (a==b);
}
int proc(pf p, int a, int b)
{
return ((*p)(a, b));
Answer: Option B
Learn more problems on : Functions
Discuss about this problem : Discuss in Forum
Point out the error in the program?
#include<stdio.h>
#include<string.h>
void modify(struct emp*);
struct emp
{
char name[20];
struct emp e = {"Sanjay", 35};
modify(&e);
printf("%s %d", e.name, e.age);
: ­­ Select ­­
D.
1
B.
Take an Another Random Test!
Go to Online Test Page
Go to Home Page
D.
­­ Select ­­
Feedback
Quality of the Test
:
Difficulty of the Test
Comments:
­1
...
Submit Feedback
Marks : 10/20
Total number of questions
:
20
Number of answered questions
:
17
Number of unanswered questions : 3

1/23/2015

00:19:45

return 0;

} void modify(struct emp *p) {

p ­>age=p­>age+2;

 

}

A. Error: in structure

A.

Error: in structure

 
B. Error: in prototype declaration unknown struct emp

B.

Error: in prototype declaration unknown struct emp

 
C. No error

C.

No error

C. No error
D. None of above

D.

None of above

 
 
 

Answer: Option B

 

Explanation:

 

The struct emp is mentioned in the prototype of the function modify() before declaring the structure.To solve this problem declare struct emp before the modify() prototype.

Learn more problems on : Structures, Unions, Enums

 

Discuss about this problem : Discuss in Forum

 
 

4.

What will be the output of the program?

 

#include<stdio.h>

 

int main()

 

{

char huge *near *far *ptr1; char near *far *huge *ptr2; char far *huge *near *ptr3; printf("%d, %d, %d\n", sizeof(**ptr1), sizeof(ptr2), sizeof(*ptr3)); return 0;

 

}

A. 4, 4, 4 B. 2, 2, 2

A.

 

4, 4, 4

 

B.

  • 2, 2, 2

C. 2, 8, 4 D. 2, 4, 8

C.

 

2, 8, 4

 

D.

  • 2, 4, 8

Answer: Option A

 

Learn more problems on : Complicated Declarations

 

Discuss about this problem : Discuss in Forum

 
  • 5. A pointer union CANNOT be created

 
 
A. Yes B. No

A.

Yes

 
A. Yes B. No

B.

No

A. Yes B. No

Answer: Option B

 

Learn more problems on : Structures, Unions, Enums

 

Discuss about this problem : Discuss in Forum

 
  • 6. Which of the following cannot be checked in a switch­case statement?

 
 
A. Character B. Integer

A.

 

Character

   

B.

  • Integer

C. Float D. enum

C.

 

Float

C. Float D. enum
 

D.

  • enum

Answer: Option C

Explanation:

The switch/case statement in the c language is defined by the language specification to use an int value, so you can not use a float value.

switch( expression ) {

case constant­expression1: statements 1;

1/23/2015

00:19:45

case constant­expression2: statements 2; case constant­expression3: statements3 ; ... ... default : statements 4;

}

The value of the 'expression' in a switch­case statement must be an integer, char, short, long. Float and double are not allowed.

Learn more problems on : Control Instructions

Discuss about this problem : Discuss in Forum

  • 7. A file written in text mode can be read back in binary mode.

 
A. Yes B. No

A.

Yes

A. Yes B. No
A. Yes B. No

B.

No

 
 

Answer: Option B

 

Explanation:

The difference is that text files contain lines (or records) of text and each of these has an end­ of­line marker automatically appended to the end of it whenever you indicate that you have reached the end of a line.

Binary files are not broken up into separate lines or records so the end­of line marker is not written when writing to a binary file.

So, we cannot read the correct the data in binary mode.

 

Learn more problems on : Input / Output

 

Discuss about this problem : Discuss in Forum

 
 
  • 8. What will be the output of the program?

 
 

#include<stdio.h>

 

int main()

 

{

float *p; printf("%d\n", sizeof(p)); return 0;

 

}

A. 2 in 16bit compiler, 4 in 32bit compiler

A.

2

in 16bit compiler, 4 in 32bit compiler

 
B. 4 in 16bit compiler, 2 in 32bit compiler

B.

4

in 16bit compiler, 2 in 32bit compiler

 
C. 4 in 16bit compiler, 4 in 32bit compiler

C.

4

in 16bit compiler, 4 in 32bit compiler

C. 4 in 16bit compiler, 4 in 32bit compiler
D. 2 in 16bit compiler, 2 in 32bit compiler

D.

2

in 16bit compiler, 2 in 32bit compiler

 
 
 

Answer: Option A

 

Explanation:

sizeof(x) returns the size of x in bytes. float *p is a pointer to a float.

 

In 16 bit compiler, the pointer size is always 2 bytes. In 32 bit compiler, the pointer size is always 4 bytes.

 

Learn more problems on : Floating Point Issues

 

Discuss about this problem : Discuss in Forum

 
 
  • 9. Which of the following are correct preprocessor directives in C? 1: #ifdef 2: #if 3: #elif 4: #undef

 
 
A. 1, 2 B. 4

A.

 

1, 2

A. 1, 2 B. 4

B.

4

C. 1, 2, 4 D. 1, 2, 3, 4

C.

 

1, 2, 4

C. 1, 2, 4 D. 1, 2, 3, 4

D.

1, 2, 3, 4

C. 1, 2, 4 D. 1, 2, 3, 4

1/23/2015

00:19:45

Answer: Option D

Explanation:

The macros #ifdef #if #elif are called conditional macros.

The macro #undef undefine the previosly declared macro symbol.

Hence all the given statements are macro preprocessor directives.

Learn more problems on : C Preprocessor

Discuss about this problem : Discuss in Forum

10. Point out the error in the following program.

#include<stdio.h> #include<stdarg.h> void display(char *s, ...); void show(char *t, ...);

int main()

{

display("Hello", 4, 12, 13, 14, 44); return 0;

} void display(char *s, ...) {

show(s, ...);

} void show(char *t, ...) {

int a; va_list ptr; va_start(ptr, s); a = va_arg(ptr, int); printf("%f", a);

}

 
A. Error: invalid function display() call

A.

Error: invalid function display() call

 
B. Error: invalid function show() call

B.

Error: invalid function show() call

 
C. No error

C.

No error

C. No error
D. Error: Rvalue required for t

D.

Error: Rvalue required for t

 

Answer: Option B

 

Explanation:

 

The call to show() is improper. This is not the way to pass variable argument list to a function.

Learn more problems on : Variable Number of Arguments

Discuss about this problem : Discuss in Forum

 

11. Union elements can be of different sizes.

 
 
A. True B. False

A.

True

A. True B. False
A. True B. False

B.

False

Answer: Option A

 

Learn more problems on : Structures, Unions, Enums

 

Discuss about this problem : Discuss in Forum

 

12. A function may have any number of return statements each returning different values.

 
A. True B. False

A.

True

A. True B. False
A. True B. False

B.

False

Answer: Option A

Explanation:

True, A function may have any number of return statements each returning different values

1/23/2015

00:19:45

and each return statements will not occur successively.

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum

  • 13. Point out the error, if any in the program. #include<stdio.h> int main() {

int i = 1; switch(i) {

printf("This is c program."); case 1:

printf("Case1");

break;

case 2:

printf("Case2");

}

break;

return 0;

}

 
A. Error: No default specified

A.

 

Error: No default specified

B. Error: Invalid printf statement after switch statement

B.

 

Error: Invalid printf statement after switch statement

 
C. No Error and prints "Case1"

C.

 

No Error and prints "Case1"

C. No Error and prints "Case1"
D. None of above

D.

 

None of above

 
 

Answer: Option C

 

Explanation:

 

switch(i) becomes switch(1), then the case 1: block is get executed. Hence it prints "Case1".

printf("This is c program."); is ignored by the compiler.

 

Hence there is no error and prints "Case1".

 

Learn more problems on : Control Instructions

 

Discuss about this problem : Discuss in Forum

 
  • 14. What will be the output of the program?

 
 

#include<stdio.h>

 

int main()

 

{

enum color{red, green, blue}; typedef enum color mycolor; mycolor m = red; printf("%d", m); return 0;

 

}

A. 1 B. 0

A.

 

1

A. 1 B. 0
  • B.

 

0

C. 2 D. red

C.

 

2

  • D.

 

red

Answer: Option B

Learn more problems on : Typedef

Discuss about this problem : Discuss in Forum

  • 15. What will be the output of the program? #include<stdio.h> int main() {

1/23/2015

00:19:45

int i=­3, j=2, k=0, m; m = ++i && ++j && ++k; printf("%d, %d, %d, %d\n", i, j, k, m); return 0;

 

}

A. ­2, 3, 1, 1 B. 2, 3, 1, 2

A.

­2, 3, 1, 1

A. ­2, 3, 1, 1 B. 2, 3, 1, 2
 

B.

  • 2, 3, 1, 2

C. 1, 2, 3, 1 D. 3, 3, 1, 2

C.

1, 2, 3, 1

 

D.

  • 3, 3, 1, 2

 
 

Answer: Option A

 

Explanation:

Step 1: int i=­3, j=2, k=0, m; here variable i, j, k, m are declared as an integer type and variable i, j, k are initialized to ­3, 2, 0 respectively.

Step 2: m = ++i && ++j && ++k; becomes m = ­2 && 3 && 1; becomes m = TRUE && TRUE; Hence this statement becomes TRUE. So it returns '1'(one). Hence m=1.

Step 3: printf("%d, %d, %d, %d\n", i, j, k, m); In the previous step the value of i,j,k are increemented by '1'(one).

Hence the output is "­2, 3, 1, 1".

 

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum

 
 

16.

What will be the output of the program?

 

#include<stdio.h>

 

int main()

 

{

int i=4, j=­1, k=0, w, x, y, z; w = i || j || k; x = i && j && k; y = i || j &&k; z = i && j || k; printf("%d, %d, %d, %d\n", w, x, y, z); return 0;

 

}

A. 1, 1, 1, 1 B. 1, 1, 0, 1

A.

1, 1, 1, 1

 

B.

  • 1, 1, 0, 1

C. 1, 0, 0, 1 D. 1, 0, 1, 1

C.

1, 0, 0, 1

 

D.

  • 1, 0, 1, 1

Answer: Option D

Explanation:

Step 1: int i=4, j=­1, k=0, w, x, y, z; here variable i, j, k, w, x, y, z are declared as an integer type and the variable i, j, k are initialized to 4, ­1, 0 respectively.

Step 2: w = i || j || k; becomes w = 4 || ­1 || 0;. Hence it returns TRUE. So, w=1

Step 3: x = i && j && k; becomes x = 4 && ­1 && 0; Hence it returns FALSE. So, x=0

Step 4: y = i || j &&k; becomes y = 4

|| ­1 && 0; Hence it returns TRUE. So, y=1

Step 5: z = i &&

j || k; becomes z = 4 && ­1

|| 0; Hence it returns TRUE. So, z=1.

Step 6: printf("%d, %d, %d, %d\n", w, x, y, z); Hence the output is "1, 0, 1, 1".

Learn more problems on : Expressions

Discuss about this problem : Discuss in Forum

  • 17. What will be the output of the program ? #include<stdio.h> int main() {

int i; char a[] = "\0"; if(printf("%s", a))

1/23/2015

00:19:45

printf("The string is empty\n"); else printf("The string is not empty\n"); return 0;

}

 
A. The string is empty B. The string is not empty

A.

The string is empty

A. The string is empty B. The string is not empty

B.

The string is not empty

C. No output D. 0

C.

No output

C. No output D. 0
C. No output D. 0

D.

0

 
 

Answer: Option B

 

Explanation:

 

The function printf() returns the number of charecters printed on the console.

Step 1: char a[] = "\0"; The variable a is declared as an array of characters and it initialized with "\0". It denotes that the string is empty.

Step 2: if(printf("%s", a)) The printf() statement does not print anything, so it returns '0'(zero). Hence the if condition is failed.

In the else part it prints "The string is not empty".

 

Learn more problems on : Strings

 

Discuss about this problem : Discuss in Forum

 
 

18. Declare the following statement? "A pointer to an array of three chars".

 
 
A. char *ptr[3](); B. char (*ptr)*[3];

A.

char *ptr[3]();

   

B.

  • char (*ptr)*[3];

 
C. char (*ptr[3])(); D. char (*ptr)[3];

C.

char (*ptr[3])();

   

D.

  • char (*ptr)[3];

C. char (*ptr[3])(); D. char (*ptr)[3];

Answer: Option D

 

Learn more problems on : Complicated Declarations

 

Discuss about this problem : Discuss in Forum

 

19. A char variable can store either an ASCII character or a Unicode character.

 
 
A. True B. False

A.

True

A. True B. False
A. True B. False

B.

False

Answer: Option A

 

Explanation:

 

Yes, we can store either an ASCII character or a Unicode character in a char variable.

Learn more problems on : Control Instructions

 

Discuss about this problem : Discuss in Forum

20. How will you free the memory allocated by the following program?

 
 

#include<stdio.h> #include<stdlib.h> #define MAXROW 3 #define MAXCOL 4

 

int main()

 

{

int **p, i, j; p = (int **) malloc(MAXROW * sizeof(int*)); return 0;

 

}

A. memfree(int p); B. dealloc(p);

A.

memfree(int p);

   

B.

  • dealloc(p);

C. malloc(p, 0); D. free(p);

C.

malloc(p, 0);

   

D.

  • free(p);

C. malloc(p, 0); D. free(p);

Answer: Option D

Learn more problems on : Memory Allocation

1/23/2015

00:19:45

Discuss about this problem : Discuss in Forum
Discuss about this problem : Discuss in Forum
Submit Test
Submit Test
1/23/2015 00:19:45 Discuss about this problem : Discuss in Forum Submit Test © 2008­2014 by IndiaBIX™Copyright | Terms of Use & Privacy Policy Contact us: info@indiabix.com Follow us on twitter! Bookmark to: http://www.indiabix.com/online­test/c­programming­test/random 8/8 " id="pdf-obj-7-13" src="pdf-obj-7-13.jpg">

© 2008­2014 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Contact us: info@indiabix.com

Bookmark to:

1/23/2015 00:19:45 Discuss about this problem : Discuss in Forum Submit Test © 2008­2014 by IndiaBIX™Copyright | Terms of Use & Privacy Policy Contact us: info@indiabix.com Follow us on twitter! Bookmark to: http://www.indiabix.com/online­test/c­programming­test/random 8/8 " id="pdf-obj-7-28" src="pdf-obj-7-28.jpg">