Commvault 2013 PSG
Commvault 2013 PSG
Page 1 / 9
When a pointer is incremented by 1, the address contained in the pointer is incremented according to the type it is pointing t
Q 10. Consider the following code
char *ptr[3] = {
the,
hello,
world
};
Correct code to print helloof the above code is:
printf(%s,*(ptr+1));
printf(%s,*ptr[0]);
printf(%s, *ptr[1]);
printf(%s,ptr[0]);
Q 11. What is the output of the following program:
#include <stdio.h>
int main()
{
int integer[] = { 0, 1, 2, 3, 4};
int *first = integer;
int *second = integer + 1;
int diff = second - first;
integer[0] += diff;
printf(%d, %d, *integer, *(integer + diff));
return 0;
Page 2 / 9
}
1,1
1,4
4,1
4,4
Q 12. Which statement is wrong given the following code?
int a[] = {5, 7, 9}, *p = a, b;
b = *p++;
b = *++p++;
b = *++p;
b = ++*p * *p++;
Q 13. Given the following code snippet, what statement do we write in line 3 and 4 to ensure there is no lost memory and no dang
#include <stdio.h>
void main() {
char *cp = (char *) malloc(10);
if(cp != NULL) strcpy(cp, "hello");
// line 3
// line 4
}
cp = NULL;
if(cp != NULL) free(cp);
if(cp != NULL) free(cp);
if(cp != NULL) free(cp);
cp = NULL;
cp = NULL;
Q 14. Consider the
main()
{
char ar[3]
char arr[]
printf(%s
}
following program:
= {a,b};
= {a,b};
%s,ar,arr);
ab ab
ab b
Runtime error
None of the above
Q 15. Consider the following code:
f(unsigned int x, unsigned int y)
{
while(x!=y)
{
if(x>y) x-=y;
else y-=x;
}
printf(%d, x > y ? y: x );
}
What does the above code do?
Compute the GCD of two numbers
Divide the largest number by the smallest number
Compute the LCM of two numbers
None of the above
Q 16. What is the output of the program?
#include <stdio.h>
void main() {
int (*Commprintf)(const char*, ...) = printf;
Commprintf("Hello World");
}
No output
Undefined symbol Commprintf
Compile Error: Prototype mismatch
Hello World
Q 17. What is the output of the program?
#include <stdio.h>
#define DEBUG 0
void main() {
#ifndef DEBUG
Page 3 / 9
printf("d1 ");
#else
printf("d2 ");
#endif
if(!DEBUG)
printf("d3 ");
else
printf("d4 ");
}
d1 d3
d2 d4
d2 d3
d1 d4
Q 18. Consider the following program:
main()
{
int i, j, k;
i =10; j=5; k=0;
k = (++i)>(++j) ? (i++) : (j++);
printf(i=%d j=%d k=%d,i,j,k);
}
The output of the above program is:
i=12 j=6 k=12
i=12 j=5 k=12
i=12 j=6 k=11
i=12 j=6 k=10
Q 19. What is the output of the program?
# include <stdio.h>
void main() {
char str[][5] = {{'h', 'e', 'l', 'l'}, {'w', 'e', 'l', 'l'}};
char str1[15] = "All is ";
printf("%s ", strcat(strchr(str1, 'l'), *(str+1)));
}
lwell
llwell
ll is well
l is well
Q 20. Consider the following program:
main()
{
char *ptr = %d%t%s;
while(*ptr++!=t)
;
printf(ptr,ptr);
}
s
%s
%d%t%s
None of the above
Q 21. What is the output of the following program?
main()
{
unsigned int i=0x53;
unsigned int j=0x12;
unsigned int sub;
_asm {
mov eax, i;
sub
eax,j;
mov sub,eax;
}
printf(%x, sub);
}
64
41
32
66
Q 22. The output of the following program is
main()
{
unsigned char c;
c = 65;
bin(c);
Page 4 / 9
}
void bin(unsigned i)
{
unsigned n=2;
for(n=n<<6; n>0; n=n/2)
{
if(i & n) printf(1);
else printf(0);
}
}
01000001
00000000
11111111
None of the above
Q 23. What is the output of the following program:
#include <stdio.h>
int main()
{
int i = 0;
int j = ~0;
unsigned int count = 0;
for ( i = 0; i > j; i--)
{
count++;
}
printf(%u, count);
return 0;
}
0
1
2^31-1
2^31
Q 24. Consider the following program:
void foo(int[]);
main()
{
static int i[6];
foo(i);
printf(%d %d, i[4], i[5]);
}
void foo(int j[])
{
j=j+2;
j[3]=5;
}
Output of the above code is:
0 5
0 0
5 0
None of the above
Q 25. Consider the following program:
main()
{
int a=2;
if(++a^++a && (a^a) || ++a)
printf(%d, a);
}
The output for the program is:
4
5
6
3
Q 26. What is the output of the program?
#include <stdio.h>
void main() {
unsigned char C = 32;
printf(" %d %d ", C ^= C , !(C & 128) && !(C & 1));
}
0 1
1 0
0 0
0 32
Page 5 / 9
Q 27. What does the macro definition DEF in the following code do?
#include <stdio.h>
#define DEF(any) (char*)(&any) - (char*)((&any) - 1)
void main()
{
int i;
char c;
double d;
printf("%d %d %d", DEF(c), DEF(i), DEF(d));
}
Gives the address the variable
Gives the size of the variable
Gives the address of the variable one element prior to the current one
Pointer subtraction
Q 28. What is the meaning of a static function in C?
It is local to a file in which it is declared
It is local to main()
The set of variables used in the function is 'static'
All the linked files can access it
Q 29. What is the output of the program?
#include <stdio.h>
void main() {
int arr[3][3] = {9, 18, 7, 16, 5, 14, 3, 12, 1};
int *ip = *arr;
printf("%d ", ++ip[4]);
printf("%d ", ++ip[2] + --ip[3]);
printf("%d ", *(++ip));
}
6 25 16
6 25 18
6 23 18
6 23 16
Q 30. What is the output of the program?
# include <stdio.h>
void main() {
int a = 4, b = 8;
while(b) {
b = b ^ a;
printf("%d %d", b << 2 | b, b >> 2 & b);
break;
}
}
60 12
15 12
60 0
15 0
Q 31. What is the error in the program?
#include <stdio.h>
#include <string.h>
#include <malloc.h>
void main() {
char *str = (char *) malloc(100);
if(str = NULL) {
printf(" Memory allocation failed ");
return;
}
strcpy(str, "HelloWorld");
printf("%5s", str);
}
Link error
Compilation error
Runtime error
No error. Output is HelloWorld
Q 32. Match the following with reference to the following program code.
#include <stdio.h>
void main()
{
int x[3][4] = {{1, 6, 9, 12}, {11, 17, 3, 2}, {20, 23, 4, 5}};
int *n = &x;
}
i)
*(*(x + 1) + 1)
1) 9
Page 6 / 9
ii) *(*x + 1) + 3
iii) *(n + 3) + 1
iv) ++(*n++) + *n
2) 13
3) 4
4) 17
i 3, ii 1, iii 2, iv 4
i 2, ii 4, iii 1, iv 3
i 4, ii 1, iii 2, iv 1
i 4, ii 3, iii 1, iv 2
Q 33. What is the output of the following program:
#include <stdio.h>
int i = 0;
int j = 0;
int func (int j)
{
return (i = (j += !i));
}
int main()
{
int i = 0;
j = func(i);
printf(%d , %d, i, j);
}
1,1
1,0
0,0
0,1
Q 34. What is the output of the program?
#include <stdio.h>
main()
{
char *p1 = "word";
char *p2;
p2 = (char *) malloc(10);
memset(p2, 'A', 10);
p2[9] = '\0';
while(*p2++ = *p1++)
printf("%s ", p2);
}
AAAAAworda AAAAAwordA AAAAwordA AAwordA
AAAAAAAAA AAAAAAAA AAAAAAA AAAAAA
AAAAAword AAAAAwor AAAAAwo AAAAAw
wordAAAAA wordAAAa wordAAA wordAA
Q 35. If "arr" is an array of 4 x 6 dimension, which expression will print the value 18 in the commented code?
#include <stdio.h>
void main() {
int arr[4][6], i, j;
int val = 1;
for(i = 0; i < 4; i++) {
for(j = 0; j < 6; j++) {
arr[i][j] = ++val;
}
}
// printf(" %d ", );
}
**arr + 4 + 6
*(*(arr + 2) + 4)
**(arr + 3) + 4
*(*(arr + 2) + 3)
Q 36. What is the output of the following problem:
#include <stdio.h>
int func (int init)
{
static int i;
i = init;
return (i++);
}
int main()
{
int i = 2;
int j = 4;
int k = 0;
for (; k < 2; k++)
{
printf(%d, func(i & j));
i = i << 1;
Page 7 / 9
j = j << 1;
}
return 0;
}
00
01
11
12
Q 37. What is the output of the following program?
#include <stdio.h>
int main()
{
int a = 3;
int b = 4;
float c = a / b;
float d = (float) (a / b);
printf(%f, c);
printf(%f, d);
return 0;
}
0.75, 0.75
0.0, 0.0
0.0, 0.75
0.75, 0.0
Q 38. To make certain that the contents of a file std.h are included only once, the contents of the file are surrounded with
#ifndef (STD)
#define STD
//program contents
#endif
#ifdef (STD)
#define STD
//program contents
#endif
#if !defined(STD)
#define STD
//program contents
#else
#undef STD
//program contents
#endif
None of the above
Q 39. What does a C program not contain on the stack at run time?
Automatic variable
Internal Static (Local to function scope) variable
Return address of function
function parameter
Q 40. What is the output of the program?
# include <stdio.h>
void main()
{
char str[][3] = {{'h', 'e', 'l'}, {'l', 'o'}, {'w'}};
char str1[20] = "C-language-is-fun";
printf("%s ", strncpy(*str, str1, sizeof(str) - 1));
}
C-lan
C-l
C-langua
C-lanuguage-is-fun
Q 41. What is the output of the following code?
#include <stdio.h>
#include <string.h>
int (*pf1)(const char *, const char *);
Page 8 / 9
demo 10
-1
demo 4
demo 4
Q 44. What would be the correct declaration for an array of pointers to functions which accept an integer and character as argum
float (*func)(int, char)[]
float (func[])(int , char)
float(*func[])(int , char)
float(func)(int, char)[]
Q 45. Which of the statements would result in compilation error? Choose
the most appropriate?
#include <stdio.h>
main()
{
static int array [] = {1, 12, 23, 44, 61};
int *iptr1 = array, *iptr2 = &array[3];
int a, b, c, d;
a = iptr1 * 2;
// Line 4
b = iptr1 + iptr2;
// Line 5
c = iptr2 / 4;
// Line 6
iptr1 = iptr2;
// Line 7
}
Line 4
Line 4 and Line 5
Line 4, Line 5 and Line 6
Line 4, Line 5, Line 6 and Line 7
Submit
Page 9 / 9