Nmit C - Aptitude Test 2

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 SJ_NMIT
S
SJ_NMIT
Community Contributor
Quizzes Created: 1 | Total Attempts: 172
| Attempts: 172 | Questions: 30
Please wait...
Question 1 / 30
0 %
0/100
Score 0/100
1. 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;} 

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.

Submit
Please wait...
About This Quiz
Nmit C - Aptitude Test 2 - Quiz

This test assesses aptitude in programming, focusing on understanding and predicting outputs of C language code snippets, covering basic to intermediate concepts.

Personalize your quiz and earn a certificate with your name on it!
2. 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;}

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

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

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.

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

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.

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

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.

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

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.

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

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

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

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.

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

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

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

Explanation

The code snippet is a C program that uses the printf function to print the values of three variables: x, x>2.

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, x
The third argument, x>>2, 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.

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

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.

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

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.

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

Explanation

array size missing in 'str' while declaration

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

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

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

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.

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

Explanation

s in out of scope in main()

Submit
17. Which of the following is integral data type?

Explanation

In c char is integral data type. It stores the ASCII value of any character constant.

Submit
18. What will be output when you will execute following code? void main(){            if(!10>-10)            printf("C");            else            printf("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.

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

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

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

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.

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

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.

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

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.

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

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

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

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.

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

Explanation

Compiler dependent- Use DEV C compiler.

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

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.

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

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.

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

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.

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

Explanation

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

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

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

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
  • Oct 14, 2016
    Quiz Created by
    SJ_NMIT
Cancel
  • All
    All (30)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What will be the output of the program ?#includeint main(){ ...
What will be the output of the program ?#includeint main(){ ...
What is the output of following program? void...
What will be the output of following program ?#include...
What will the Output of the following? main()  ...
What is the output of the following program? void...
What will be the Output of the Following #include void...
What will be the output of the program ?#includeint *check(static int,...
What will be the Output of the following #include...
What will be printed as the result of the operation...
What will be the output of the program ?#includeint main(){ ...
What will be the Output of the following program ? void...
What will be the output of the following .. ?#include...
What is the output of following program? void...
What is the output of following program? void...
What is the output of following program? void...
Which of the following is integral data type?
What will be output when you will execute following code? void...
What will be output when you will execute following...
What will be the output of the program if the size of pointer is...
What will be the output of following program ? #include...
What is the output of following program? void...
What will be the output of the following ?#include <stdio.h>int...
: what is the output of following program? void...
What is the output of following program? void abc(int a, int...
What is the output of following program? void...
What will be the Output of the program ?#include <stdio.h>void...
What will be the output of the following ?#include void main(){char...
 What value of c will get...
What will be the Output of the following ?#include <stdio.h>int...
Alert!

Advertisement