# Medhamilan2011 - Sri Vishnu Engg College For Women::Bhimavaram

Approved & Edited by ProProfs Editorial Team
At ProProfs Quizzes, our dedicated in-house team of experts takes pride in their work. With a sharp eye for detail, they meticulously review each quiz. This ensures that every quiz, taken by over 100 million users, meets our standards of accuracy, clarity, and engagement.
| Written by Abhiram
A
Abhiram
Community Contributor
Quizzes Created: 3 | Total Attempts: 847
Questions: 40 | Attempts: 164  Settings  C Programming Contest

• 1.

### main(){        int  const *p=5;        printf(“%d”,++(*p));}

• A.

6

• B.

Error

• C.

Garbage

• D.

5

B. Error
Explanation
The given code has a syntax error. The variable "p" is declared as a constant pointer to an integer and is assigned the value 5. However, the value 5 cannot be assigned to a pointer variable directly. It should be assigned the address of a variable instead. Therefore, the code will result in an error.

Rate this question:

• 2.

### main(){         printf(“%d”,  -   -2);}

• A.

1

• B.

2

• C.

Error

• D.

-2

B. 2
Explanation
The given code snippet is using the printf function to print the value of -2. The format specifier used is "%d" which is used for printing integers. The "  -  -2" is a unary negation operator applied twice on the value 2, resulting in -2. Therefore, the correct answer is 2.

Rate this question:

• 3.

### #define  abc(p)   p*p main(){ int a=2; k=abc(a+1); printf(“%d”.k);}

• A.

9

• B.

5

• C.

3

• D.

Error

B. 5
Explanation
The code snippet defines a macro "abc" which takes an argument "p" and returns the square of "p". In the main function, an integer variable "a" is declared and assigned a value of 2. Then, the macro "abc" is called with the argument "a+1", which evaluates to 3. The result of the macro call is assigned to an undeclared variable "k". Finally, the printf statement tries to print the value of "k", but since "k" is not declared, it will result in an error. Therefore, the correct answer is "error".

Rate this question:

• 4.

### #define  int  char main(){ int i=65; printf(“%d”,sizeof(i));

• A.

Error

• B.

2

• C.

1

• D.

65

C. 1
Explanation
The code snippet defines a macro `int` as `char`, which means that whenever `int` is used in the code, it will be replaced with `char`. In the `main` function, an integer variable `i` is declared and initialized with the value 65. The `sizeof` operator is then used to determine the size of `i`. Since `i` is of type `char` due to the macro definition, the `sizeof` operator will return the size of a `char` data type, which is 1 byte. Therefore, the correct answer is 1.

Rate this question:

• 5.

### #define f(g1,g2)  g1 # # g2 main(){ int  var12 = 100, var=200; printf(“%d”,f(var,12));}

• A.

Error

• B.

100

• C.

200

• D.

Garbage

B. 100
Explanation
The code defines a macro function "f" that concatenates two arguments using the ## operator. In the main function, it declares two variables "var12" and "var" with initial values. Then, it uses the printf function to print the result of calling the macro function "f" with arguments "var" and 12. Since the macro function concatenates the arguments without any additional operations, the result is 100.

Rate this question:

• 6.

### main(){ int  i=1; switch(i){ default:  printf(“zero”); case 1: printf(“one”);break; case 2: printf(“two”);break; case 3: printf(“three”);break;} }

• A.

None

• B.

Zero one two three

• C.

Zero

• D.

One

D. One
Explanation
The code snippet declares a variable i and initializes it to 1. It then enters a switch statement with i as the expression. Since the value of i is 1, it matches the case 1 and executes the corresponding printf statement, which prints "one". Therefore, the correct answer is "one".

Rate this question:

• 7.

### main(){ printf(“%d”,scanf(“%d”,&k);}

• A.

1

• B.

Garbage value

• C.

Error

• D.

2

A. 1
Explanation
The given code snippet is trying to print the value returned by the scanf function. The scanf function is used to read input from the user and returns the number of successfully scanned items. In this case, the code is trying to scan an integer value and store it in the variable 'k'. However, the code is missing a closing parenthesis after '&k' which will result in a syntax error. Therefore, the correct answer is 'error'.

Rate this question:

• 8.

### main(){ int i=10; i=!i>14; printf(“%d”,i);} a.

• A.

B

• B.

C

• C.

14

• D.

0

D. 0
Explanation
The expression "!i>14" evaluates to false because the value of i (10) is not greater than 14. The "!" operator is a logical NOT operator, so it negates the result of the comparison. Therefore, the value of "i" becomes false, which is represented as 0 in C programming. The printf statement then prints the value of "i" which is 0.

Rate this question:

• 9.

### #define  clrscr()  50 main(){ printf(“svecw”); clrscr(); printf(“50”);}

• A.

Error

• B.

Svecw

• C.

50

• D.

Svecw 50

C. 50
Explanation
The given code snippet defines a macro `clrscr()` which is defined as 50. In the main function, the string "svecw" is printed using `printf()`, then the `clrscr()` macro is called which is replaced with 50, and finally the string "50" is printed using `printf()`. Therefore, the output of the code will be "svecw50".

Rate this question:

• 10.

### main(){ int i=1; do while(i++<=3); printf(“hello friends”);}

• A.

Error

• B.

Hello friends

• C.

1

• D.

None

A. Error
Explanation
The given code will result in an error. This is because the combination of the do-while and while loop is not valid syntax in C programming. The correct syntax would be either using a do-while loop or a while loop separately, but not both together in this manner.

Rate this question:

• 11.

### .#include main(){ char *str =”yahoo”; char *ptr =str; char least =127; while(*ptr++) least = (*ptr printf(“%d”,least); } what is the output?

• A.

0

• B.

127

• C.

Yahoo

• D.

Y

B. 127
Explanation
The given code has a syntax error, as the closing parenthesis is missing after "*ptr". Therefore, the code will not compile and there will be no output.

Rate this question:

• 12.

### Main(){ int i =300; char *ptr = &i; *++ptr=2; printf(“%d”,i); } what is output?

• A.

556

• B.

300

• C.

2

• D.

302

A. 556
Explanation
In this code, the variable 'i' is declared and assigned a value of 300. Then, a character pointer 'ptr' is declared and assigned the address of 'i'. The code then increments the pointer and assigns the value 2 to the memory location pointed by 'ptr'. Finally, the value of 'i' is printed using the printf function. Since 'ptr' points to the memory location of 'i', when the value 2 is assigned to that location, the value of 'i' is changed to 556. Therefore, the output of the code is 556.

Rate this question:

• 13.

### Main(){ void swap(); int x = 45, y = 15; swap(&x,&y); printf(“x = %d y=%d”x,y); } void swap(int *a, int *b){ *a^=*b, *b^=*a, *a^ = *b; what is the output?

• A.

x = 15, y =45

• B.

X =15, y =15

• C.

X =45 ,y =15

• D.

X =45 y = 45

A. x = 15, y =45
Explanation
The output will be x = 15, y = 45. This is because the swap function is called with the addresses of x and y as arguments. Inside the swap function, the values at those addresses are swapped using the XOR (^) operator. After the swap, the value of x becomes 15 and the value of y becomes 45.

Rate this question:

• 14.

### Main(){ int i = 10, j =20; j = i ,j?(i,j)?i :j:j; printf(“%d%d”,i,j); }what is the output?

• A.

20 20

• B.

20 10

• C.

10 20

• D.

10 10

D. 10 10
Explanation
The output of this code will be "10 10".
In the given code, the expression "j = i ,j?(i,j)?i :j:j;" is evaluated.
Since the value of j is not 0, the inner ternary operator "(i,j)?i :j" is executed.
In this ternary operator, the comma operator is used which evaluates both expressions i and j, but only returns the value of j.
Therefore, the value of j remains unchanged and is assigned back to j.
Finally, the values of i and j are printed, which are both 10.

Rate this question:

• 15.

### Main() { void vpointer; char cHar = ‘g’, *cHarpointer = “GOOGLE”; int j = 40; vpointer = &cHar; printf(“%c”,*(char*)vpointer); vpointer = &j; printf(“%d”,*(int *)vpointer); vpointer = cHarpointer; printf(“%s”,(char*)vpointer +3); } what is the output?

• A.

G40GLE

• B.

• C.

G0GLE

• D.

G4GOO

A. G40GLE
Explanation
The code first assigns the address of the variable 'cHar' to the void pointer 'vpointer'. Then it prints the value at that address, which is 'g'. Next, it assigns the address of the variable 'j' to 'vpointer' and prints the value at that address, which is '40'. Finally, it assigns the value of the variable 'cHarpointer' to 'vpointer' and prints the string starting from the 4th character, which is 'GLE'. Therefore, the output is 'g40GLE'.

Rate this question:

• 16.

### Main()             {             int k=1;             printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE");             }

• A.

1==1 is TRUE

• B.

1==1 is FALSE

• C.

0==1 is TRUE

• D.

0==1 is FALSE

A. 1==1 is TRUE
Explanation
In the given code, the variable k is initialized as 1. The printf statement is used to print the result of the expression "k==1". Since the value of k is indeed 1, the expression evaluates to true and the output will be "1==1 is TRUE".

Rate this question:

• 17.

### #define FALSE -1             #define TRUE   1             #define NULL   0             main() {                if(NULL)                         puts("NULL");                else if(FALSE)                         puts("TRUE");                else                         puts("FALSE");                }

• A.

TRUE

• B.

.false

• C.

Error

• D.

. none

A. TRUE
Explanation
The correct answer is TRUE. In the given code, the if statement checks if the value of NULL is true. Since NULL is defined as 0, which is considered false in C, the condition evaluates to false. Then, the else if statement checks if the value of FALSE is true. Since FALSE is defined as -1, which is considered true in C, the condition evaluates to true. Therefore, the statement "puts("TRUE")" is executed, resulting in the output "TRUE".

Rate this question:

• 18.

### Main()             {             main();             }

• A.

Compile error

• B.

Stack overflow

• C.

• D.

None

B. Stack overflow
Explanation
The given code is a recursive function that calls itself within the main function. As a result, each time the main function is called, it will keep calling itself indefinitely, leading to an infinite loop. This will eventually cause the program to run out of stack space, resulting in a stack overflow error. Therefore, the correct answer is stack overflow.

Rate this question:

• 19.

### Main( ) {  static int  a[ ]   = {0,1,2,3,4};  int  *p[ ] = {a,a+1,a+2,a+3,a+4};  int  **ptr =  p;  ptr++;  printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr);  *ptr++;  printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr);  *++ptr;  printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr);  ++*ptr;        printf(“\n %d  %d  %d”, ptr-p, *ptr-a, **ptr); }

• A.

111 111 111 111

• B.

111 222 333 444

• C.

222 222 222 222

• D.

None

B. 111 222 333 444
Explanation
The given code initializes an array 'a' with values 0, 1, 2, 3, and 4. It then declares an array of pointers 'p' and assigns the addresses of elements in 'a' to each pointer in 'p'. The variable 'ptr' is a pointer to a pointer and is assigned the address of the first element in 'p'.

In the first printf statement, 'ptr-p' gives the difference between the addresses of 'ptr' and 'p', which is 1. '*ptr-a' gives the difference between the value pointed to by 'ptr' and the first element of 'a', which is 111. '**ptr' gives the value pointed to by the value pointed to by 'ptr', which is also 111.

In the subsequent statements, '*ptr++' increments the value of 'ptr' by 1, and the printf statements give the updated values accordingly.

Rate this question:

• 20.

### Main( ) {   int a = {{{2,4},{7,8},{3,4}},{{2,2},{2,3},{3,4}}};   printf(“%u %u %u %d \n”,a,*a,**a,***a);         printf(“%u %u %u %d \n”,a+1,*a+1,**a+1,***a+1);        }

• A.

100, 100, 100, 2 114, 104, 102, 3

• B.

100,100,2 114,114,114,3

• C.

100,100,100,2 114,114,102,3

• D.

101,101,101,1 104,104,104,3

A. 100, 100, 100, 2 114, 104, 102, 3
Explanation
The given code declares a three-dimensional array 'a' with dimensions 2x3x2. It initializes the array with specific values. The first printf statement prints the values at the memory addresses 'a', '*a', '**a', and '***a'. Since 'a' represents the address of the first element of the array, '*a' represents the address of the first row, '**a' represents the address of the first element of the first row, and '***a' represents the value at the first element of the first row.

The second printf statement prints the values at the memory addresses 'a+1', '*a+1', '**a+1', and '***a+1'. 'a+1' represents the address of the second element of the array, '*a+1' represents the address of the second row, '**a+1' represents the address of the first element of the second row, and '***a+1' represents the value at the first element of the second row.

Therefore, the correct answer is 100, 100, 100, 2 and 114, 104, 102, 3.

Rate this question:

• 21.

### Main() {  int i=400,j=300;  printf("%d..%d"); }

• A.

300..400

• B.

400..300

• C.

400..400

• D.

error

B. 400..300
Explanation

In the given code, the variables i and j are initialized with the values 400 and 300 respectively. However, the printf statement is missing the placeholders for the variables. As a result, the output will be 400..300.

Rate this question:

• 22.

### 1.       main() {  char *p;  p="Hello";  printf("%c\n",*&*p); }

• A.

Error

• B.

Hello

• C.

H

• D.

ello

C. H
Explanation
In this code, the pointer variable "p" is assigned the address of the string "Hello". The expression "*&*p" is then used as an argument to the printf function. The "&*p" part of the expression cancels each other out, leaving just "p". Since "p" is a pointer to a character, it can be dereferenced with the "*" operator to get the value it is pointing to, which is the first character of the string "Hello", which is "H". Therefore, the output of the code is "H".

Rate this question:

• 23.

### 1.       enum colors {BLACK,BLUE,GREEN}  main() {    printf("%d..%d..%d",BLACK,BLUE,GREEN);     return(1); }

• A.

0..1..2

• B.

BLACK..BLUE..GREEN

• C.

1..2..3

• D.

Error

A. 0..1..2
Explanation
The given code defines an enum called "colors" with three values: BLACK, BLUE, and GREEN. In the main function, it prints the values of BLACK, BLUE, and GREEN using the printf function. The values of BLACK, BLUE, and GREEN are assigned automatically starting from 0, so the output will be 0..1..2.

Rate this question:

• 24.

### Main() {             char s[ ]="man";             int i;             for(i=0;s[ i ];i++)             printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]); }

• A.

mmmm aaaa nnnn

• B.

Error

• C.

mmmm aaa nn

• D.

Man

A. mmmm aaaa nnnn
Explanation
The given code is a C program that prints a string "man" in a specific format. The for loop iterates through each character in the string "s". Inside the loop, the printf statement is used to print the current character, the character at the current index using pointer arithmetic, and the character at the current index using array indexing.

In this case, the output will be "mmmm aaaa nnnn" because the printf statement is formatted to print the characters in a specific pattern. The characters 'm', 'a', and 'n' are printed repeatedly to form the desired pattern.

Rate this question:

• 25.

### 1.       main() {              int c[ ]={2.8,3.4,4,6.7,5};              int j,*p=c,*q=c;              for(j=0;j<5;j++) {                         printf(" %d ",*c);                         ++q;     }              for(j=0;j<5;j++){ printf(" %d ",*p); ++p;     } }

• A.

2 3 4 5 2 3 4 6 5

• B.

2 2 2 2 2 2 3 4 6 5

• C.

2 2 2 3 4 5 6 4 5 6

• D.

None

B. 2 2 2 2 2 2 3 4 6 5
Explanation
The given code declares an array c with 5 elements and initializes it with values 2.8, 3.4, 4, 6.7, and 5. It also declares two pointers p and q, both pointing to the first element of the array c.

In the first for loop, the pointer q is incremented in each iteration, but the value of c is printed instead of the value pointed to by q. This results in printing the first element of the array c (2) five times.

In the second for loop, the pointer p is incremented in each iteration, and the value pointed to by p is printed. This results in printing the elements of the array c (2.8, 3.4, 4, 6.7, and 5).

Therefore, the correct answer is "2 2 2 2 2 2 3 4 6 5".

Rate this question:

• 26.

### 1.       main() {             extern int i;             i=20; printf("%d",i); }

• A.

Linker Error : Undefined symbol '_i'

• B.

comiler error

• C.

20

• D.

Error

A. Linker Error : Undefined symbol '_i'
Explanation
The given code snippet is attempting to access a variable named 'i' which is declared as an external variable. However, there is no definition or declaration of this variable in the current file or any other file that is being linked. Therefore, when the linker tries to resolve the reference to 'i', it cannot find it and throws a linker error stating that the symbol '_i' is undefined.

Rate this question:

• 27.

### Main() {               printf("%x",-1<<4); }

• A.

Fff0

• B.

-1

• C.

145

• D.

Error

A. Fff0
Explanation
The code is using the left shift operator (

Rate this question:

• 28.

### Main() {             char string[]="Hello World";             display(string); } void display(char *string) {             printf("%s",string); }

• A.

Hello

• B.

World

• C.

Compiler Error : Type mismatch in redeclaration of function display

• D.

Hello World

C. Compiler Error : Type mismatch in redeclaration of function display
Explanation
The given code snippet is attempting to call the function display() to print the string "Hello World". However, the function display() has not been declared or defined before it is being called in the main() function. This results in a compiler error stating a type mismatch in the redeclaration of the function display. To fix this error, the display() function should be declared or defined before it is called in the main() function.

Rate this question:

• 29.

### #include main() { char s[]={'a','b','c','\n','c','\0'}; char *p,*str,*str1; p=&s; str=p; str1=s; printf("%d",++*p + ++*str1-32); }

• A.

77

• B.

66

• C.

76

• D.

55

A. 77
Explanation
The code snippet declares an array 's' with characters 'a', 'b', 'c', a line break character, 'c', and a backslash character followed by the number 48. It then declares three pointers 'p', 'str', and 'str1'. 'p' is assigned the address of the fourth element of the array (line break character), 'str' is assigned the value of 'p', and 'str1' is assigned the address of the first element of the array. The printf statement increments the value pointed to by 'p' and 'str1', which results in 'd' and 'c' respectively. The ASCII value of 'd' is 100 and 'c' is 99. Adding them together and subtracting 32 gives the result of 77.

Rate this question:

• 30.

### 1.       #include main() { int a = { {10,2,3,4}, {5,6,7,8}  }; int *p,*q; p=&a; *q=***a; printf("%d----%d",*p,*q); }

• A.

Error

• B.

Garbage value

• C.

10

• D.

5

B. Garbage value
Explanation
The code is trying to access the value at the address `a`, which is outside the bounds of the array `a`. This results in undefined behavior, and in this case, it is giving a garbage value. The variable `p` is assigned the address of `a`, and when `*p` is dereferenced, it accesses the garbage value. The variable `q` is assigned `***a`, which is equivalent to `a`, so `*q` accesses the value 10.

Rate this question:

• 31.

### 1.       #include main() { struct xx {       int x=3;       char name[]="hello";  }; struct xx *s; printf("%d",s->x); printf("%s",s->name); }

• A.

none

• B.

• C.

Runtime error

• D.

Compiler error

D. Compiler error
Explanation
The code is trying to assign initial values to the variables inside the structure definition. However, in C language, you cannot assign initial values to variables inside a structure definition. This results in a compiler error.

Rate this question:

• 32.

### #include main() { struct xx { int x; struct yy { char s;             struct xx *p; }; struct yy *q; }; }

• A.

• B.

Compiler error

• C.

runtime error

• D.

None

B. Compiler error
Explanation
The given code will result in a compiler error. This is because the struct yy is nested inside the struct xx, but it is being used before it is defined. In C, a struct must be defined before it is used. To fix this error, the struct yy should be defined before the struct xx.

Rate this question:

• 33.

### Main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); }

• A.

44444 .

• B.

455554

• C.

45545

• D.

.55555

C. 45545
Explanation
The given code snippet is a C program that prints a series of numbers using the printf function. The program initializes a variable i with the value 5. The printf statement contains multiple placeholders for the variable i. The order of the post-increment, post-decrement, pre-increment, and pre-decrement operators in the printf statement determines the final output. In this case, the output is 45545.

Rate this question:

• 34.

### #define square(x) x*x main() { int i; i = 64/square(4); printf("%d",i); }

• A.

46

• B.

64

• C.

66

• D.

56

B. 64
Explanation
The code defines a macro called square which takes an argument x and returns x*x. In the main function, the variable i is assigned the value of 64 divided by the square of 4, which is 64/16=4. Finally, the value of i is printed, which is 4.

Rate this question:

• 35.

### #include #define a 10 main() { #define a 50 printf("%d",a); }

• A.

51

• B.

50

• C.

52

• D.

60

B. 50
Explanation
The code starts by defining a macro "a" with the value of 10. Then, within the main function, another macro "a" is defined with the value of 50. When the printf statement is executed, it prints the value of "a", which is 50. Therefore, the output of the code is 50.

Rate this question:

• 36.

### 1.       main() { printf("%p",main); }

• A.

Garbage

• B.

01FA

• C.

Compile error

• D.

01X2F

B. 01FA
Explanation
The given code snippet is written in C programming language. It defines a main function which uses the printf function to print the address of the main function itself. The %p format specifier is used to print a pointer value. In this case, the address of the main function is printed. The correct answer is "01FA" which represents the hexadecimal address of the main function.

Rate this question:

• 37.

### Void main() {  char far *farther,*farthest;    printf("%d..%d",sizeof(farther),sizeof(farthest));     }

• A.

4..2

• B.

2..2

• C.

2..1

• D.

4..1

A. 4..2
Explanation
The code declares two pointers to type char, "farther" and "farthest". The "sizeof" operator is then used to determine the size of these pointers. The size of a pointer is typically dependent on the architecture and compiler being used. In this case, the size of "farther" is 4 bytes and the size of "farthest" is 2 bytes. This suggests that the architecture being used has 4-byte pointers.

Rate this question:

• 38.

### Main() {    static char names={"pascal","ada","cobol","fortran","perl"};     int i;     char *t;     t=names;     names=names;     names=t;     for (i=0;i<=4;i++)             printf("%s",names[i]); }

• A.

Compiler error

• B.

• C.

Runtime error

• D.

None

A. Compiler error
Explanation
The given code will result in a compiler error because it is trying to assign a value to an array name, which is not allowed in C. Array names are non-modifiable lvalues, meaning they cannot be assigned a new value.

Rate this question:

• 39.

### Main() { int i=0;   for(;i++;printf("%d",i)) ; printf("%d",i); }

• A.

1

• B.

0

• C.

2

• D.

Error

A. 1
Explanation
This code will result in an infinite loop. The for loop is missing the condition statement, so it will continue to loop indefinitely. The printf statement inside the loop will print the value of i each time it loops. However, since i is incremented after the condition check, the first value printed will be 1. Therefore, the correct answer is 1.

Rate this question:

• 40.

### Main() { printf("%d", out); } int out=100;

• A.

• B.

Runtime error

• C.

Compiler error

• D.

None Back to top