1.
Assume that an int variable takes 4 bytes and a char variable takes 1 byte
Correct Answer
A. Number of elements between two pointer are: 5.
Number of bytes between two pointers are: 20
Explanation
The correct answer is that the number of elements between two pointers is 5 and the number of bytes between the two pointers is 20. This means that there are 5 elements stored in memory between the two pointers, and each element takes up 4 bytes of memory. Therefore, the total number of bytes between the two pointers is 20.
2.
What would be the equivalent pointer expression for referring the array element a[i][j][k][l]
Correct Answer
B. *(*(*(*(a+i)+j)+k)+l)
Explanation
The given correct answer, *(*(*(*(a+i)+j)+k)+l), is the equivalent pointer expression for referring to the array element a[i][j][k][l]. The expression breaks down the array access into multiple levels of indirection, starting with *(a+i) to access the i-th element of the array, then adding j to access the j-th element of the resulting array, then adding k to access the k-th element, and finally adding l to access the l-th element. The * operator is used at each level to dereference the pointer and access the value stored at that memory location.
3.
What will be the value of var for the following C statement?
var = strcmp("Hello", "World");
Correct Answer
A. -1
Explanation
The value of var will be -1 because strcmp() is a function in C that compares two strings. It returns an integer value that indicates the relationship between the two strings. If the first string is less than the second string, it returns a negative value. In this case, "Hello" is less than "World", so var is assigned the value -1.
4.
Which pre-defined function returns a pointer to the last occurence of a character in a string?
Correct Answer
B. Strrchr(s, c);
Explanation
The strrchr(s, c) function returns a pointer to the last occurrence of the character 'c' in the string 's'. This function starts searching for the character from the end of the string and returns a pointer to that location.
5.
The following C expression can be substituted for?
if (isalpha(c) && isdigit(c))
Correct Answer
D. None of the mentioned
Explanation
The given C expression cannot be substituted for any of the options provided. The expression checks if the character is both an alphabet and a digit, while the options provided either check if the character is alphanumeric or a combination of alphabet and digit. Therefore, none of the mentioned options can be used as a substitute for the given expression.
6.
Which of the following structure declaration will throw an
error?
Correct Answer
D. None of the mentioned
Explanation
All of the given structure declarations are correct and will not throw an error. Therefore, the correct answer is "None of the mentioned".
7.
How will you print \n on the screen?
Correct Answer
D. Printf (“\\n”)
Explanation
The correct answer is "printf (“\”)" because this statement uses the printf function to print the string "\" on the screen. The backslash (\) is used to escape the forward slash (/) character, so it is printed as part of the string.
8.
Assuming, integer is 2 byte, What will be the output of the program?
#include<stdio.h>
int main()
{
printf("%x\n", -1>>1);
return 0;
}
Correct Answer
A. Ffff
Explanation
The program is using the right shift operator (>>) to shift the bits of -1 by 1 position to the right. Since the integer is assumed to be 2 bytes, -1 in binary is represented as 1111 1111 1111 1111. Shifting the bits to the right by 1 position results in 1111 1111 1111 1110, which is equal to fffe in hexadecimal. However, the program is using the printf function with the format specifier "%x" which prints the value in hexadecimal. Therefore, the output of the program will be ffff.
9.
What will be the output of the program?
#include<stdio.h>
#define SQUARE(x) x*x
int main()
{
float s=10, u=30, t=2, a;
a = 2*(s-u*t)/SQUARE(t);
printf("Result = %f", a);
return 0;
}
Correct Answer
A.
Result = -100.00000
Explanation
The program calculates the value of 'a' using the formula 2*(s-u*t)/SQUARE(t), where 's' is 10, 'u' is 30, 't' is 2, and SQUARE(x) is a macro that squares the value of 'x'.
Plugging in the given values, the calculation becomes 2*(10-30*2)/2*2, which simplifies to 2*(-50)/4, and further simplifies to -100/4.
Therefore, the value of 'a' is -100.00000, which is the correct answer.
10.
What will be the output of the program ?
#include<stdio.h>
#include<string.h>
int main()
{
char str1[20] = "Hello", str2[20] = " World";
printf("%s\n", strcpy(str2, strcat(str1, str2)));
return 0;
}
Correct Answer
C. Hello World
Explanation
The program will output "Hello World". This is because the strcat function is used to concatenate str1 and str2, resulting in "Hello World". Then, the strcpy function is used to copy the concatenated string into str2. Finally, the printf function is used to print the contents of str2, which is "Hello World".
11.
What will be the output of the program?
#include<stdio.h>
int main()
{
unsigned int res;
res = (64 >>(2+1-2)) & (~(1<<2));
printf("%d\n", res);
return 0;
}
Correct Answer
A. 32
Explanation
The program uses bitwise operators to perform operations on the number 64. The expression `(64 >> (2+1-2)) & (~(1 1) & (~4)`.
First, the number 64 is right-shifted by 1, resulting in 32.
Then, the number 4 is converted to its binary representation, which is 100. The bitwise NOT operator (~) is applied to 4, resulting in 011.
Finally, the bitwise AND operator (&) is applied between 32 and 011, resulting in 000.
Therefore, the output of the program is 0.
12.
What will be the output of the program ?
#include<stdio.h>
int main()
{
union var
{
int a, b;
};
union var v;
v.a=10;
v.b=20;
printf("%d\n", v.a);
return 0;
}
Correct Answer
B. 20
Explanation
The program defines a union named "var" which has two members, "a" and "b" of type int. In the main function, a variable "v" of type "var" is declared. The values of "a" and "b" in "v" are assigned as 10 and 20 respectively. The printf statement then prints the value of "a" which is 20. Therefore, the output of the program will be 20.
13.
Which of the following statements are correct about the program?
#include<stdio.h>
int main()
{
unsigned int num;
int i;
scanf("%u", &num);
for(i=0; i<16; i++)
{
printf("%d", (num<<i & 1<<15)?1:0);
}
return 0;
Correct Answer
C. It prints binary equivalent num
Explanation
The given program takes an unsigned integer as input and prints its binary equivalent. The for loop iterates 16 times, each time checking if the ith bit of the input number is 1 or 0. If it is 1, it prints 1, otherwise it prints 0. Therefore, the program prints the binary representation of the input number.
14.
What will be the output of the program assuming that the array begins at location 1002?
#include<stdio.h>
int main()
{
int a[2][3][4] = { {1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 1, 2},
{2, 1, 4, 7, 6, 7, 8, 9, 0, 0, 0, 0} };
printf("%u, %u, %u, %d\n", a, *a, **a, ***a);
return 0;
}
Correct Answer
C. 1002, 1002, 1002, 1
Explanation
The output of the program will be "1002, 1002, 1002, 1". The variable "a" is a 3-dimensional array, and when we print the values, we use the format specifier "%u" for unsigned integer and "%d" for integer.
In the printf statement, "a" represents the address of the first element of the array, which is 1002. "*a" represents the value at that address, which is also 1002. "**a" represents the value at the address of the first element of the first sub-array, which is again 1002. "***a" represents the value at the address of the first element of the first sub-array of the first sub-array, which is 1.
15.
Find the missing statement ....to get the output - India
#include<stdio.h>
#include<string.h>
int main()
{
char str[] = "XXXX\0\India\0";
printf("%s\n", str);
return 0;
}
Correct Answer
A. India
Explanation
The missing statement is "printf("%s", str);" which prints the value of the variable "str" followed by a line break. In this case, the value of "str" is "India" because the string "XXXX" is overwritten by the string "India" using the null character "\0" as a delimiter.
16.
Find the missing statement ..in order to get the address of prt
#include <stdio.h>
int main()
{
int a=10;
int *ptr,XXXXXX;
ptr=&a;
pptr=&ptr;
}
Correct Answer
A. **pptr
Explanation
The correct answer is **pptr because it is the missing statement that is required to get the address of prt. In the given code, pptr is declared as a pointer to a pointer and it is assigned the address of ptr using the & operator. By dereferencing **pptr, we can access the value stored in ptr, which is the address of a.
17.
Find the missing statement in order to get output 4
#include<stdio.h>
int main()
{
char a[20];
int n=XXXXXX(a,"cbitt");
printf("value of n is %d",n);
return 0;}
Correct Answer
B. Sprintf
Explanation
The missing statement in order to get the output 4 is "sprintf". The "sprintf" function is used to store formatted data into a string variable. In this case, it is used to store the value returned by the function "XXXXXX(a, "cbitt")" into the variable "n". The value of "n" is then printed using the "printf" function.
18.
Find the missing statement in order to swap two number a and b
a=XXXXX;
b=a-b;
a=a-b;
Correct Answer
A. A+b
Explanation
To swap two numbers a and b, we need to assign the value of a to variable b and the value of b to variable a. In the given code, the missing statement is "b=a+b". This statement assigns the sum of a and b to variable b. By doing this, the original value of a is stored in b. Then, the code proceeds to assign the difference of a and b to variable a, which effectively swaps the values of a and b. Therefore, the correct answer is a+b.
19.
In the following code to find if a number is armstrong number or not..Find the missing statement
#include<stdio.h>
#include<conio.h>
main()
{
int n,r,sum=0,temp;
clrscr(); /
printf("enter the number=");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
sum=sum+(XXXXX);
n=n/10;
}
if(temp==sum)
printf("armstrong number ");
else
printf("not armstrong number");
getch();
}
Correct Answer
A. R*r*r
Explanation
In order to find if a number is an Armstrong number or not, we need to calculate the sum of the cubes of its digits. The missing statement in the code should be "r*r*r" which represents the cube of the digit "r". This statement should be added to the line "sum=sum+(XXXXX)" in the code.
20.
In order to get the same output twice find the missing statement
#include <stdio.h>
int x = 0;
void main()
{
int *ptr = &x;
printf("%p\n", ptr);
XXXX;
printf("%p\n ", ptr);
}
Correct Answer
A. X++;
Explanation
The missing statement is "x++;" which increments the value of x by 1. This means that after the missing statement is added, the value of x will be incremented by 1.
21.
In order to get output 0 Find the missing statement..
include <stdio.h>
void main()
{
int x = 0;
int *ptr = &x;
printf("%d\n", XXX);
}
Correct Answer
A. *ptr
Explanation
The correct answer is *ptr. In order to print the value of x, which is 0, we need to dereference the pointer variable ptr using the * operator. This will give us the value stored at the memory location pointed to by ptr, which is 0 in this case.