BreakInterview

1. Predict the output of the following program.
#include
int main()
{
 char *ptr = "breakinterview";
 printf("%c", *&*&*ptr);
 return 0;
}

b
address of the string
breakinterview
compilation error

2. Predict the output of the following program.
#include
int main()
{
 char *ptr = "breakinterview";
 printf("%s", *&*&ptr);
 return 0;
}

b
address of the string
breakinterview
compilation error

3. What is a pointer pointing to a memory location that has been deleted (or freed) is called ?

Void Pointer
Null pointer
Wild Pointer
Dangling Pointer

4. What is a pointer which has not been initialized to anything (not even NULL) called?

Void Pointer
Null pointer
Wild pointer
Dangling Pointer

5. Pick the best statement for the above C program snippet.
#include "stdio.h" 
int main()
{
 void *pVoid;
 pVoid = (void*)0;
 printf("%lu",sizeof(pVoid));
 return 0;
}

Assigning (void *)0 to pVoid isn’t correct because memory hasn’t been allocated. That’s why no compile error but it’ll result in run time error.
Assigning (void *)0 to pVoid isn’t correct because a hard coded value (here zero i.e. 0) can’t assigned to any pointer. That’s why it’ll result in compile error.
No compile issue and no run time issue. And the size of the void pointer i.e. pVoid would equal to size of int.
sizeof() operator isn’t defined for a pointer of void type.

6. Suppose that in a C program snippet, followings statements are used.
i) sizeof(int);
ii) sizeof(int*);
iii) sizeof(int**);
Assuming size of pointer is 4 bytes and size of int is also 4 bytes, pick the most correct answer from the given options.

Only i) would compile successfully and it would return size as 4.
i), ii) and iii) would compile successfully and size of each would be same i.e. 4
i), ii) and iii) would compile successfully but the size of each would be different and would be decided at run time.
ii) and iii) would result in compile error but i) would compile and result in size as 4.

7. Assume int is 4 bytes, char is 1 byte and float is 4 bytes. Also, assume that pointer size is 4 bytes
char *pChar;
int *pInt;
float *pFloat;
 
sizeof(pChar);
sizeof(pInt);
sizeof(pFloat);

4 4 4
1 4 4
1 4 8
None of the above

8.
void fun(int *p) 
{ 
  int q = 10; 
  p = &q; 
}     
  
int main() 
{ 
  int r = 20; 
  int *p = &r; 
  fun(p); 
  printf("%d", *p); 
  return 0; 
}

10
20
Compiler Error
Runtime Error

9.
void fun(int **pptr)
{
  static int q = 10;
  *pptr = &q;
}

int main()
{
  int r = 20;
  int *p = &r;
  fun(&p);
  printf("%d", *p);
  return 0;
}

10
20
Compiler Error
Runtime Error

10. Assume sizeof an integer and a pointer is 4 byte. Output?
#include 
 
#define R 10
#define C 20
 
int main()
{
   int (*p)[R][C];
   printf("%d",  sizeof(*p));
  return 0;
}

200
4
800
80