ExamVeda
Login
Home
41
The operator > and < are meaningful when used with pointers, if
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
42
The declaration
int (*p) [5];
means
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
43
Comment on the following?
const int *ptr;
Discuss
Answer & Solution
Answer: Option A
Solution:
int * : pointer to int
int const * : pointer to const int
int * const : const pointer to int
int const * const : const pointer to const int

Now the first const can be on either side of the type so:

const int * == int const *
const int * const == int const * const

So the above declaration is pointer to const int. Which means,we cannot change the value pointed by ptr.
44
Determine Output:
#include<stdio.h>
void main()
{
      int *ptr, a=10;
      ptr = &a;
      *ptr += 1;
      printf("%d, %d", *ptr, a);
}
Discuss
Answer & Solution
Answer: Option D
Solution:

Address of variable a is assigned to the integer pointer ptr.
Due to the statement;
*ptr += 1;
value at address pointing by ptr incremented by 1.
As the value at address is changed so variable a also get the updated value.

45
A function 'p' that accepts a pointer to a character as argument and returns a pointer to an array of integer can be declared as
Discuss
Answer & Solution
Answer: Option A
Solution:
OPTION 'A' AS CORRECT...
THERE ARE SEVERAL DIFFERENT USES OF POINTERS IN C...THEY ARE
(1) int *p;
// p is a pointer to an integer quantity
(2) int *p[10];
// p is a 10-element array of pointers to integer quantities
(3) int (*p)[10];
// p is a pointer to a 10-element integer array
(4) int *p(void);
// p is a function that returns a pointer to an integer quantity
(5) int p(char *a);
// p is a function that accepts an argument which is a pointer to a character returns an integer quantity
(6) int *p(char *a);
// p is a function that accepts an argument which is a pointer to a character returns a pointer to an integer quantity.
(7) int (*p)(char *a);
// p is pointer to a function that accepts an argument which is a pointer to a character returns an integer quantity.
(8) int (*p(char *a))[10];
// p is a function that accepts an argument which is a pointer to a character returns a pointer to a 10-element integer array.
(9) int p(char (*a)[]);
// p is a function that accepts an argument which is a pointer to a character array returns an integer quantity.
(10) int p(char *a[]);
// p is a function that accepts an argument which is a array of pointers to characters returns an integer quantity
(11) int *p(char a[]);
// p is a function that accepts an argument which is a character array returns a pointer to an integer quantity
(12) int *p(char (*a)[]);
// p is a function that accepts an argument which is a pointer to a character array returns a pointer to an integer quantity
(13) int *p(char *a[]);
// p is a function that accepts an argument which is an array of pointers to characters
// returns a pointer to an integer quantity
(14) int (*p)(char (*a)[]);
// p is pointer to a function that accepts an argument which is a pointer to a character array returns an integer quantity
(15) int *(*p)(char (*a)[]);
// p is pointer to a function that accepts an argument which is a pointer to a character array returns a pointer to an integer quantity
(16) int *(*p)(char *a[]);
// p is pointer to a function that accepts an argument which is a array of pointers to characters returns a pointer to an integer quantity
(17) int (*p[10])(void);
// p is 10-element array of pointers to functions; each function returns an integer quantity
(18) int (*p[10])(char a);
// p is 10-element array of pointers to functions; each function accepts an argument which is a character and returns an integer quantity
(19) int *(*p[10])(char a);
// p is 10-element array of pointers to functions; each function accepts an argument which is a character and returns a pointer to an integer quantity
(20) int *(*p[10])(char *a);
// p is 10-element array of pointers to functions; each function accepts an argument which is a pointer to a character and returns a pointer to an integer
46
What will be printed after compiling and running the following code?
main() 
{ 
    char *p; 
    printf("%d %d",sizeof(*p), sizeof(p));
}
Discuss
Answer & Solution
Answer: Option B
Solution:

The sizeof() operator gives the number of bytes taken by its operand. p is a character pointer, which needs one byte for storing its value (a character). Hence sizeof(*p) gives a value of 1. Since it needs two bytes to store the address of the character pointer sizeof(p) gives 2.

47
What will be the output of the following program code?
#include <stdio.h>
void main()
{
    int i=3, *j, **k;
    j = &i;
    k = &j;
    printf("%d%d%d", *j, **k, *(*k));
}
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
48
Which of the following is the correct way of declaring a float pointer:
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
49
Find the output of the following program.
void main()
{
   char *msg = "hi";
   printf(msg);
}
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
50
Find the output of the following program.
void main()
{
   int array[10];
   int *i = &array[2], *j = &array[5];
   int diff = j-i;
   printf("%d", diff);
}
Discuss
Answer & Solution
Answer: Option A
Solution:

When subtracting pointers you get the number of elements between those addresses, not the number of bytes.