ExamVeda
Login
Home
31
Determine Output:
void main()
{
      char far *farther, *farthest;
      printf("%d..%d", sizeof(farther), sizeof(farthest));
}
Discuss
Answer & Solution
Answer: Option C
Solution:
In the given C program code snippet:

void main()
{
      char far *farther, *farthest;
      printf("%d..%d", sizeof(farther), sizeof(farthest));
}


The sizeof operator is used to determine the size, in bytes, of a variable or data type.

1. **farther** and **farthest** are both pointers of type **char***. In C, the size of a pointer is typically **4 bytes** on a 32-bit system or **8 bytes** on a 64-bit system. Assuming a standard 32-bit architecture, the size of both pointers would be **4 bytes**. 2. Therefore, the output of the printf function will be: - sizeof(farther) = 4 - sizeof(farthest) = 4

The printf statement prints these two sizes, resulting in the output **"4..4"**.

Hence, the correct answer is **Option C: 4..4**.
32
Determine Output:
main()
{
      char *str1 = "abcd";
      char str2[] = "abcd";
      printf("%d %d %d", sizeof(str1), sizeof(str2), sizeof("abcd"));
}
Discuss
Answer & Solution
Answer: Option C
Solution:

In first sizeof, str1 is a character pointer so it gives you the size of the pointer variable. In second sizeof the name str2 indicates the name of the array whose size is 5 (including the 'null' termination character). The third sizeof is similar to the second one.

33
Choose the best answer.
Prior to using a pointer variable
Discuss
Answer & Solution
Answer: Option C
Solution:
Using a pointer variable, without initializing it, will be disastrous, as it will have a garbage value.
34
Comment on the following pointer declaration?
int *ptr, p;
Discuss
Answer & Solution
Answer: Option A
Solution:
int *ptr, p;

ptr is declared as a pointer to an integer because of the `*` symbol next to it. This means that `ptr` can hold the address of an integer variable.

p is declared as a regular integer variable, not a pointer. The absence of the `*` symbol means that `p` will hold an integer value directly, not an address.

Key Points:
- ptr: Pointer to integer, can store addresses of integer variables.
- p: Regular integer variable, cannot store addresses.
35
What will be the output?
main() 
{ 
      char *p; 
      p = "Hello"; 
      printf("%cn",*&*p); 
}
Discuss
Answer & Solution
Answer: Option B
Solution:

* is a dereference operator & is a reference operator. They can be applied any number of times provided it is meaningful. Here p points to the first character in the string "Hello". *p dereferences it and so its value is H. Again & references it to an address and * dereferences it to the value H.

36
Determine output:
#include <stdio.h>
void main()
{
      char *p = NULL;
      char *q = 0;
      if(p)
            printf(" p ");
      else
            printf("nullp");
      if(q)
            printf("q");
      else
            printf(" nullq");
}
Discuss
Answer & Solution
Answer: Option D
Solution:

char *p = NULL is same as char *q = 0.
In both declarations p and q are initialized to null.

37
The address operator &, cannot act on
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
38
The statement int **a;
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
39
What will be the output of the following program?
#include<stdio.h>
void main()
{
      int i = 10;
      void *p = &i;
      printf("%d\n", (int)*p);
}
Discuss
Answer & Solution
Answer: Option A
Solution:

p is pointer of type void.

40
What will be the output of the following program code?
#include<stdio.h>
void main()
{
      int i = 10;
      void *p = &i;
      printf("%f", *(float *)p);
}
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board