ExamVeda
Login
Home
41
Determine Output:
void main()
{
      char *p;
      p="%d\n";
      p++;
      p++;
      printf(p-2, 300);
}
Discuss
Answer & Solution
Answer: Option B
Solution:

The pointer points to % since it is incremented twice and again decremented by 2, it points to '%d\n' and 300 is printed.

42
Determine Output:
void 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;
      }
}
Discuss
Answer & Solution
Answer: Option D
Solution:

Initially pointer c is assigned to both p and q. In the first loop, since only q is incremented and not c , the value 2 will be printed 5 times. In second loop p itself is incremented. So the values 2 3 4 6 5 will be printed.

43
Determine Output:
void main()
{
      int a[] = {10,20,30,40,50}, j, *p;
      for(j=0; j<5; j++){
            printf("%d" ,*a);
            a++;
      }
      p = a;
      for(j=0; j<5; j++){
            printf("%d" ,*p); 
            p++;
      }
}
Discuss
Answer & Solution
Answer: Option C
Solution:

Compiler error: lvalue required
Error is in line with statement a++. The operand must be an lvalue and may be of any of scalar type for any operator, array name only when subscripted is an lvalue. Simply array name is a non-modifiable lvalue.

44
Determine Output:
#include<stdio.h>
void main()
{
      char s[]={'a','b','c','n','c','\0'}; 
      char *p, *str, *str1; 
      p=&s[3]; 
      str=p;
      str1=s;
      printf("%c", ++*p + ++*str1-32);
}
Discuss
Answer & Solution
Answer: Option C
Solution:

p is pointing to character '\n'. str1 is pointing to character 'a'.
++*p: "p is pointing to '\n' and that is incremented by one." the ASCII value of '\n' is 10. then it is incremented to 11. the value of ++*p is 11.
++*str1: "str1 is pointing to 'a' that is incremented by 1 and it becomes 'b'. ASCII value of 'b' is 98.
Both 11 and 98 is added and result is subtracted from 32.
i.e. (11+98-32) = 77("M").

45
Determine Output:
void main()
{
      static char *s[] = {"black", "white", "yellow", "violet"};
      char **ptr[] = {s+3, s+2, s+1, s}, ***p;
      p = ptr;
      ++p; 
      printf("%s",*--*++p + 3); 
}
Discuss
Answer & Solution
Answer: Option D
Solution:

In this problem we have an array of char pointers "s" pointing to start of 4 strings. Then we have ptr which is a pointer to a pointer of type char and a variable p which is a pointer to a pointer to a pointer of type char. p holds the initial value of ptr, i.e. p = s+3. The next statement increment value in p by 1 , thus now value of p = s+2. In the printf statement the expression is evaluated as follows: *++p causes gets value s+1 then the pre decrement is executed and we get s+1-1 = s which is pointing to the word "black". The indirection operator now gets the value from the array of s and adds 3 to the starting address. The string is printed starting from this position. Thus, the output is 'ck'.

46
What will be the output of the following C code?
#include<stdio.h>
main()
{
    int n;
    n=f1(4);
    printf("%d",n);
}
f1(int x)
{
    int b;
    if(x==1)
        return 1;
    else
        b=x*f1(x-1);
        return b;
}
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
47
In the absence of a exit condition in a recursive function, the following error is given . . . . . . . .
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
48
What is the output of this C code?
#include <stdio.h>
main()
{
    if (sizeof(int) > -1)
        printf("True");
    else
        printf("False");
}
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
49
What will be the value of the following assignment expression?
(x = foo())!= 1 considering foo() returns 2
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
50
Suppose we have: int a=100; (signed by default).
If we want to convert this to an unsigned long integer, we can do this by making the following small change:
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board