Medhamilan2011 - Sri Vishnu Engg College For Women::Bhimavaram

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Abhiram
A
Abhiram
Community Contributor
Quizzes Created: 3 | Total Attempts: 933
| Attempts: 164 | Questions: 40
Please wait...
Question 1 / 40
0 %
0/100
Score 0/100
1. #define square(x) x*x
main()
{
int i;
i = 64/square(4);
printf("%d",i);
}


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.

Submit
Please wait...
About This Quiz
Medhamilan2011 - Sri Vishnu Engg College For Women::Bhimavaram - Quiz

The 'Medhamilan2011 - Sri Vishnu Engg College for Women::Bhimavaram' quiz assesses knowledge in C\/C++ programming. It tackles topics like pointers, preprocessor directives, and control structures, essential for students in computer science and programming courses.

Tell us your name to personalize your report, certificate & get on the leaderboard!
2. #include
#define a 10
main()
{
#define a 50
printf("%d",a);
}


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.

Submit
3. main()
            {
            int k=1;
            printf("%d==1 is ""%s",k,k==1?"TRUE":"FALSE");
            }

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".

Submit
4. 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);
}

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.

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

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".

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

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.

Submit
7. main()
{
int i=5;
printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);
}


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.

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

Explanation

The code is trying to access the value at the address `a[2][2][2]`, 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[2][2][2]`, and when `*p` is dereferenced, it accesses the garbage value. The variable `q` is assigned `***a`, which is equivalent to `a[0][0][0]`, so `*q` accesses the value 10.

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

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.

Submit
10. main()
{
printf("%d", out);
}

int out=100;

Explanation

The given code will result in a compiler error because the variable "out" is being referenced before it is declared. In C, variables need to be declared before they can be used. To fix this error, the declaration of the variable "out" should be moved above the printf statement.

Submit
11. 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?

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.

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

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.

Submit
13. main()
{
int i=0;
 
for(;i++;printf("%d",i)) ;
printf("%d",i);
}

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.

Submit
14. main()
{
   static char names[5][20]={"pascal","ada","cobol","fortran","perl"};
    int i;
    char *t;
    t=names[3];
    names[3]=names[4];
    names[4]=t;
    for (i=0;i<=4;i++)
           
printf("%s",names[i]);
}

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.

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

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.

Submit
16. main()
            {
            main();
            }


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.

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

Explanation

The correct answer is 400..300.

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.

Submit
18. main()
{
            char string[]="Hello World";
            display(string);
}
void display(char *string)
{
            printf("%s",string);
}

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.

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

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.

Submit
20. 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;     }
}

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".

Submit
21. 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?

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'.

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


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".

Submit
23. main()
{
              printf("%x",-1<<4);
}


Explanation

The code is using the left shift operator (

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

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.

Submit
25.
     #define  clrscr()  50 main(){ printf(“svecw”); clrscr(); printf(“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".

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

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.

Submit
27. void main()
{
 char far *farther,*farthest;
 
 printf("%d..%d",sizeof(farther),sizeof(farthest));
  
 }

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.

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

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.

Submit
29. main( )
{
  int a[2][3][2] = {{{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);
       }

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.

Submit
30. 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]);
}

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.

Submit
31. 1.       main()
{
            extern int i;
            i=20;
printf("%d",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.

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

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.

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

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".

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

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.

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

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".

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

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.

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

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.

Submit
38.    main(){         printf(“%d”,  -   -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.

Submit
39.    main(){ printf(“%d”,scanf(“%d”,&k);}
 

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'.

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

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.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 21, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 21, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Mar 01, 2011
    Quiz Created by
    Abhiram
Cancel
  • All
    All (40)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
#define ...
#include #define a 10 main() { #define a 50 printf("%d",a); }
Main() ...
Main( ...
  main(){ ...
Main(){ ...
Main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); }
1.       #include ...
   main(){ ...
Main() { printf("%d", out); } int out=100;
Main(){ ...
.#include ...
Main() ...
Main() ...
#include ...
Main() ...
Main() {  int i=400,j=300;  printf("%d..%d"); }
Main() ...
1.       #include ...
1.       main() ...
Main() ...
#define ...
Main() ...
  main(){ ...
     #define  clrscr()  ...
1.       enum colors {BLACK,BLUE,GREEN} ...
Void ...
    #define  int  ...
Main( ...
Main() ...
1.       main() ...
     main(){ ...
1.       main() ...
#include ...
   #define  abc(p)   ...
  #define ...
1.       main() ...
   main(){ ...
   main(){ ...
Main(){ ...
Alert!

Advertisement