Nmit C - Aptitude Test 2

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By SJ_NMIT
S
SJ_NMIT
Community Contributor
Quizzes Created: 1 | Total Attempts: 160
Questions: 30 | Attempts: 160

SettingsSettingsSettings
Nmit C - Aptitude Test 2 - Quiz

.


Questions and Answers
  • 1. 

    What will be the Output of the following program ? void main(){   const char var='A';   ++var;   printf("%c",var);}

    • A.

      A

    • B.

      B

    • C.

      ERROR

    • D.

      66

    Correct Answer
    C. ERROR
    Explanation
    The program will result in an error because the variable "var" is declared as a constant using the "const" keyword. Constants cannot be modified, so the attempt to increment "var" using the "++" operator will cause a compilation error.

    Rate this question:

  • 2. 

    What will be the Output of the Following #include void main(){    int x=(20 || 40 ) && (10);    printf("x= %d",x);}

    • A.

      X= 1

    • B.

      X=60

    • C.

      X= 70

    • D.

      X= 0

    Correct Answer
    A. X= 1
    Explanation
    1)(20 || 40) .... both are non zero values, will return 1.
    2)(1) && 10 .... both are non zero values, hence output will be 1

    Rate this question:

  • 3. 

    What will be the Output of the program ?#include <stdio.h>void main(){    int intVar=20,x;    x= ++intVar,intVar++,++intVar;    printf("Value of intVar=%d, x=%d",intVar,x);}

    • A.

      Value of intVar=23, x=21

    • B.

      Value of intVar=23, x=23

    • C.

      ERROR

    • D.

      Value of intVar=21, x=21

    Correct Answer
    A. Value of intVar=23, x=21
    Explanation
    The program initializes the variable "intVar" with a value of 20. Then, the expression "x= ++intVar,intVar++,++intVar" is evaluated. The comma operator evaluates each expression from left to right and the result of the entire expression is the value of the rightmost expression.

    First, "++intVar" increments the value of "intVar" to 21. Then, "intVar++" increments the value of "intVar" to 22, but the result of this expression is still 21. Finally, "++intVar" increments the value of "intVar" to 23.

    Therefore, the value of "intVar" is 23 and the value of "x" is 21.

    Rate this question:

  • 4. 

     What value of c will get printedmain(){            int a,b,c;            a=10;            b=20;            c=printf("%d",a)+ ++b;            printf("%d",c);}

    • A.

      23

    • B.

      22

    • C.

      30

    • D.

      Compilation Error

    Correct Answer
    A. 23
    Explanation
    printf() will return no. of bytes it printed
    Expression becomes
    c = 2 + ++b;
    then value of b is incremented before addition

    Rate this question:

  • 5. 

    What will be the output of the program ?#includeint main(){    int i=3, *j, k;    j = &i;    printf("%d\n", i**j*i+*j);    return 0;} 

    • A.

      30

    • B.

      27

    • C.

      9

    • D.

      3

    Correct Answer
    A. 30
    Explanation
    The program initializes the variable i with a value of 3. It then declares a pointer variable j and assigns the address of i to j. The printf statement calculates the value of i multiplied by the value pointed to by j (which is the value of i itself) multiplied by i again, and adds the value pointed to by j (which is again the value of i). This results in the calculation 3 * 3 * 3 + 3, which equals 30. Therefore, the output of the program would be 30.

    Rate this question:

  • 6. 

    What will be the output of following program ?#include <stdio.h>int main(){     int i=-1,j=-1,k=0,l=2,m;     m=i++&&j++&&k++||l++;     printf("%d %d %d %d %d",i,j,k,l,m);     return 0;}

    • A.

      0 0 1 2 1

    • B.

      0 0 1 3 2

    • C.

      0 0 1 3 1

    • D.

      0 1 1 3 1

    Correct Answer
    C. 0 0 1 3 1
    Explanation
    In the given program, the variables i, j, k, l are initialized with -1, -1, 0, 2 respectively.
    The expression i++&&j++&&k++||l++ is evaluated from left to right.
    Since i is -1, it is first incremented to 0 and then checked. Since it is not 0, the evaluation continues.
    Next, j is also incremented from -1 to 0, but since it is still 0, the evaluation stops and the result is 0.
    Therefore, i and j remain 0, k is incremented to 1, l is incremented to 3, and m is assigned the value 1.
    The printf statement then prints the values of i, j, k, l, and m which are 0, 0, 1, 3, and 1 respectively.

    Rate this question:

  • 7. 

    What will be the output of the program ?#includeint main(){    char str[20] = "Hello";    char *const p=str;    *p='M';    printf("%s\n", str);    return 0;}

    • A.

      Mello

    • B.

      Hello

    • C.

      Hmello

    • D.

      MHello

    Correct Answer
    A. Mello
    Explanation
    The program will output "Mello". The variable `str` is declared as a character array and initialized with the string "Hello". The pointer `p` is declared as a constant pointer to a character and assigned the address of `str`. Since `p` is a constant pointer, it cannot be reassigned to point to a different memory location. However, the value at the memory location it points to can be modified. In this case, `*p = 'M'` changes the first character of the string from 'H' to 'M'. Therefore, when `str` is printed using `printf`, it will display "Mello".

    Rate this question:

  • 8. 

    What is the output of following program? void abc(int a, int b){            printf("%d%d",++a,++b);            }void main(){            int a=10;            abc(++a,a++);            abc(a++,++a);            printf("%d",a);}

    • A.

      13 11 14 14 14

    • B.

      13 12 12 13 14

    • C.

      13 11 13 14 14

    • D.

      13 12 14 14 14

    Correct Answer
    A. 13 11 14 14 14
    Explanation
    Compiler dependent- Use DEV C compiler.

    Rate this question:

  • 9. 

    What will be the output of following program ? #include <stdio.h>int main(){    int MAX=10;    int array[MAX];    printf("size of array is = %d",sizeof(array));    return 0;}

    • A.

      Size of array is = 20

    • B.

      Size of array is = 40

    • C.

      Size of array is = 4

    • D.

      Error

    Correct Answer
    B. Size of array is = 40
    Explanation
    The size of the array is determined by multiplying the number of elements in the array by the size of each element. In this case, the array has 10 elements and each element is an integer, which typically has a size of 4 bytes. Therefore, the size of the array is 10 * 4 = 40 bytes.

    Rate this question:

  • 10. 

    What will be the output of the program ?#includeint main(){    char *str;    str = "%s";    printf(str, "K\n");    return 0;}

    • A.

      Error

    • B.

      No output

    • C.

      K

    • D.

      %s

    Correct Answer
    C. K
    Explanation
    The program will output "K". The variable "str" is assigned the value "%s", which is a format specifier for a string. When the printf function is called, it uses the value of "str" as the format string and "K" as the argument to be printed. Therefore, "K" is printed as the output.

    Rate this question:

  • 11. 

    What will be the output of the program ?#includeint *check(static int, static int);int main(){    int *c;    c = check(10, 20);    printf("%d\n", c);    return 0;}int *check(static int i, static int j){    int *p, *q;    p = &i;    q = &j;    if(i >= 45)        return (p);    else        return (q);}

    • A.

      10

    • B.

      20

    • C.

      Error:non portable pointer convertion

    • D.

      Error:cannot use static for function parameters

    Correct Answer
    D. Error:cannot use static for function parameters
    Explanation
    The program will output "Error: cannot use static for function parameters." This is because the function "check" has two parameters declared as "static int," which is not allowed in C programming. The keyword "static" is used to declare variables with static storage duration, but it cannot be used for function parameters. Hence, the program will result in a compilation error.

    Rate this question:

  • 12. 

    What will be the Output of the following #include <stdio.h>int main(){    char X[10]={'A'},i;    for(i=0; i<10; i++)        printf("%d ",X[i]);    return 0;}

    • A.

      A 0 0 0 0 0 0 0 0 0

    • B.

      65 0 0 0 0 0 0 0 0 0

    • C.

      ERROR

    • D.

      A 32 32 32 32 32 32 32 32 32

    Correct Answer
    B. 65 0 0 0 0 0 0 0 0 0
    Explanation
    The given code initializes an array X with only one element 'A' and the rest of the elements are not initialized. The loop runs for 10 iterations and tries to print the elements of array X. Since the rest of the elements are not initialized, they will have garbage values. The ASCII value of 'A' is 65, so the first element of X will be printed as 65 and the rest of the elements will be printed as 0 due to garbage values. Therefore, the output will be "65 0 0 0 0 0 0 0 0 0".

    Rate this question:

  • 13. 

    What will be the output of the program if the size of pointer is 4-bytes?#includeint main(){    printf("%d, %d\n", sizeof(NULL), sizeof(""));    return 0;}

    • A.

      2,1

    • B.

      2,2

    • C.

      4,1

    • D.

      4,2

    Correct Answer
    C. 4,1
    Explanation
    The output of the program will be "4,1". The sizeof(NULL) will return the size of a pointer, which is 4 bytes in this case. The sizeof("") will return the size of an empty string, which is 1 byte.

    Rate this question:

  • 14. 

    What is the output of following program? void f1(){            static int s=5;            ++s;            printf("%d",s);} main(){            f1();            f1();            printf("%d",s);}

    • A.

      Error

    • B.

      6 6 6

    • C.

      6 7 7

    • D.

      6 7 6

    Correct Answer
    A. Error
    Explanation
    s in out of scope in main()

    Rate this question:

  • 15. 

    What will be printed as the result of the operation below:main() {             int x=5;             printf("%d,%d,%d",x,x<<2,x>>2);}

    • A.

      5,20,1

    • B.

      0

    • C.

      1

    • D.

      Compilation Error

    Correct Answer
    A. 5,20,1
    Explanation
    The code snippet is a C program that uses the printf function to print the values of three variables: x, x2.

    In the given program, the value of x is initialized to 5.

    In the printf statement, the first argument is "%d,%d,%d", which specifies the format for printing three integers.

    The second argument, x2, is a bitwise right shift operation on x. This shifts the binary representation of x two places to the right, resulting in 1.

    Therefore, the program will print "5,20,1" as the output.

    Rate this question:

  • 16. 

    What will be the output of the following ?#include void main(){char cnt=0;for(;cnt++;printf("%d",cnt)) ;printf("%d",cnt);}

    • A.

      1

    • B.

      0111.... upto 127 times

    • C.

      0

    • D.

      0111 ... infinite

    Correct Answer
    A. 1
    Explanation
    The program will output "1".

    In the for loop, the condition is always true because the increment operation is executed after the condition is checked. So, the loop will keep running indefinitely.

    Inside the loop, the printf statement will print the value of "cnt" which starts at 0 and gets incremented by 1 in each iteration. So, it will print "0" first, then "1", and so on.

    However, since the loop is infinite, the program will not reach the second printf statement, and only "1" will be printed.

    Rate this question:

  • 17. 

    What is the output of following program? void main(){            int a,b,c,d;            a=b=c=d=1;            a=++b>1 || ++c>1 && ++d>1;            printf("%d%d%d%d",a,b,c,d);}

    • A.

      1211

    • B.

      1121

    • C.

      1221

    • D.

      1212

    Correct Answer
    A. 1211
    Explanation
    The program initializes variables a, b, c, and d to 1. Then, it evaluates the expression `++b>1 || ++c>1 && ++d>1`.

    Since the `++b>1` is true (b becomes 2), the first part of the expression is true and the second part (`++c>1 && ++d>1`) is not evaluated.

    Therefore, the value of a remains 1, b becomes 2, and c and d remain 1.

    The printf statement prints the values of a, b, c, and d, which are 1211.

    Rate this question:

  • 18. 

    What will be the output of the following .. ?#include <stdio.h>#include <string.h> int main(){char str[];strcpy(str,"Hello");printf("%s",str);return 0;}

    • A.

      Error

    • B.

      Hello

    • C.

      NULL

    • D.

      Str

    Correct Answer
    A. Error
    Explanation
    array size missing in 'str' while declaration

    Rate this question:

  • 19. 

    : what is the output of following program? void main(){            printf("%d%d",47%5,47%-5);            printf("%d%d%d",-47%5,-47%-5,5%7);}

    • A.

      2,2,-2,-2,5

    • B.

      2,-2,-2,-2,5

    • C.

      2,-2,2,-2,5

    • D.

      2,2,-2,-2,0

    Correct Answer
    A. 2,2,-2,-2,5
    Explanation
    The program uses the printf function to print the results of various arithmetic operations.

    In the first printf statement, the expression 47%5 calculates the remainder when 47 is divided by 5, which is 2. The expression 47%-5 calculates the remainder when 47 is divided by -5, which is also 2. Therefore, the first part of the output is 2,2.

    In the second printf statement, the expression -47%5 calculates the remainder when -47 is divided by 5, which is -2. The expression -47%-5 calculates the remainder when -47 is divided by -5, which is also -2. Finally, the expression 5%7 calculates the remainder when 5 is divided by 7, which is 5. Therefore, the second part of the output is -2,-2,5.

    Combining the two parts, the output of the program is 2,2,-2,-2,5.

    Rate this question:

  • 20. 

    What is the output of following program? void main(){            int a=2;            switch(a)            {                        case 1: printf("A");                        break;                        case 2: printf("B");                        continue;                        case 3: printf("C");                        break;                        case 4; printf("D");                        default: printf("E");            }}

    • A.

      ERROR

    • B.

      B E

    • C.

      B C E

    • D.

      B C D E

    Correct Answer
    A. ERROR
    Explanation
    The program will result in an error because there is a syntax error in the code. The case statement for the value 4 is written as "case 4;" instead of "case 4:". The missing colon after the value 4 will cause a compilation error. Therefore, the correct answer is "ERROR".

    Rate this question:

  • 21. 

    What is the output of the following program? void main(){            int a;            a=1;            a++ * ++a;            printf("%d",a);}

    • A.

      3

    • B.

      4

    • C.

      6

    • D.

      2

    Correct Answer
    A. 3
    Explanation
    The output of the program is 3.

    In the expression "a++ * ++a", the value of "a" is first incremented by 1 (a++), so "a" becomes 2. Then, it is incremented again by 1 (++a), so "a" becomes 3.

    The multiplication operation is then performed between the original value of "a" (2) and the incremented value of "a" (3), resulting in 6. However, since the result of the expression is not assigned to any variable, it is not stored or used in the program.

    Finally, the value of "a" (3) is printed using the printf statement, resulting in the output of 3.

    Rate this question:

  • 22. 

    Which of the following is integral data type?

    • A.

      Char

    • B.

      Void

    • C.

      Float

    • D.

      Double

    Correct Answer
    A. Char
    Explanation
    In c char is integral data type. It stores the ASCII value of any character constant.

    Rate this question:

  • 23. 

    What is the output of following program? void main(){            printf("%d%d%d",-10^9, -10|9, -10&9);}

    • A.

      -1 -1 0

    • B.

      1 1 0

    • C.

      1 0 1

    • D.

      -1 0 0

    Correct Answer
    A. -1 -1 0
    Explanation
    The program uses the bitwise operators ^, |, and & to perform operations on the numbers -10 and 9.

    -10^9 performs a bitwise XOR operation between -10 and 9, resulting in -1.

    -10|9 performs a bitwise OR operation between -10 and 9, resulting in -1.

    -10&9 performs a bitwise AND operation between -10 and 9, resulting in 0.

    Therefore, the output of the program is -1 -1 0.

    Rate this question:

  • 24. 

    What will be the output of the following ?#include <stdio.h>int main(){char    *str    []={"AAAAA","BBBBB","CCCCC","DDDDD"};char    **sptr  []={str+3,str+2,str+1,str};char    ***pp; pp=sptr;++pp;printf("%s",**++pp+2);return 0;}

    • A.

      BBB

    • B.

      BBBB

    • C.

      CCC

    • D.

      Error

    Correct Answer
    A. BBB
    Explanation
    The code declares a character array `str` with 4 elements, each containing a string of 5 characters. It also declares a pointer array `sptr` with 4 elements, each pointing to one of the strings in `str` in reverse order. It then declares a triple pointer `pp` and assigns it the address of the first element of `sptr`.

    The expression `**++pp+2` increments `pp` to point to the second element of `sptr`, then dereferences twice to get the value at that memory location, which is the string "BBBBB". Adding 2 to this string gives "BBB".

    Therefore, the output will be "BBB".

    Rate this question:

  • 25. 

    What is the output of following program? void main(){            int a;            a=10;            a*=10+2;            printf("%d",a);}

    • A.

      120

    • B.

      102

    • C.

      100

    • D.

      22

    Correct Answer
    A. 120
    Explanation
    The program initializes the variable 'a' to 10. Then, it multiplies 'a' by the expression '10+2', which evaluates to 12. Therefore, the value of 'a' becomes 10 * 12 = 120. Finally, the program prints the value of 'a', which is 120.

    Rate this question:

  • 26. 

    What will be output when you will execute following code? #include "stdio.h"int main(){    char a=250;    int expr;    expr= a+ !a + ~a + ++a;    printf("%d",expr);    return 0;}

    • A.

      -6

    • B.

      249

    • C.

      250

    • D.

      0

    Correct Answer
    A. -6
    Explanation
    char a = 250;
    250 is beyond the range of signed char. Its corresponding cyclic value is: -6
    So, a = -6
    Consider on the expression:
    expr= a+ !a + ~a + ++a;
    Operator! , ~ and ++ have equal precedence. And it associative is right to left.
    So, First ++ operator will perform the operation. So value a will -5
    Now,
    Expr = -5 + !-5 + ~-5 + -5
    = -5 + !-5 + 4 - 5
    = -5 + 0 + 4 -5
    = -6

    Rate this question:

  • 27. 

    What will be the Output of the following ?#include <stdio.h>int main(){char ch=10;void *ptr=&ch;printf("%d,%d",*(char*)ptr,++(*(char*)ptr));return 0;}

    • A.

      11,11

    • B.

      10,11

    • C.

      10,10

    • D.

      Error

    Correct Answer
    A. 11,11
    Explanation
    The program declares a character variable 'ch' and initializes it with the value 10. Then, a void pointer 'ptr' is declared and assigned the address of 'ch'. The printf statement prints the value at the address pointed by 'ptr' (which is 10) and then increments the value at that address by 1 (to 11). Therefore, the output will be "10,11".

    Rate this question:

  • 28. 

    What is the output of following program? void main(){            int i=10;            printf("%d%d%d",++i, i++, ++i);}

    • A.

      13 11 11

    • B.

      11 11 13

    • C.

      11 12 13

    • D.

      13 12 11

    Correct Answer
    A. 13 11 11
    Explanation
    The output of the program is 13 11 11. This is because the order of evaluation of the expressions in the printf statement is not defined. In this case, the behavior is undefined and can vary depending on the compiler.

    Rate this question:

  • 29. 

    What will the Output of the following? main()    {    static int var = 5;    printf("%d ",var--);    if(var)        main();    }

    • A.

      54321

    • B.

      Error

    • C.

      545454

    • D.

      56789

    Correct Answer
    A. 54321
    Explanation
    The program starts by printing the value of the static variable "var", which is initially 5. Then, it decrements the value of "var" by 1. After that, it checks if "var" is still non-zero. Since "var" is now 4, the condition is true and the program calls the "main()" function again. This process continues until "var" becomes 0. Each time the "main()" function is called recursively, the value of "var" is printed and decremented. Therefore, the output will be 54321.

    Rate this question:

  • 30. 

    What will be output when you will execute following code? void main(){            if(!10>-10)            printf("C");            else            printf("C++");}

    • A.

      C

    • B.

      Nothing display on screen

    • C.

      C++

    • D.

      None of these

    Correct Answer
    A. C
    Explanation
    The output of the code will be "C". This is because the condition in the if statement is "!10>-10", which evaluates to "true". Therefore, the code inside the if block will be executed, and "C" will be printed on the screen.

    Rate this question:

Quiz Review Timeline +

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
  • Oct 14, 2016
    Quiz Created by
    SJ_NMIT
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.