Thursday, 14 June 2018

ch-5 Pointer



1.6 What will be the output of the following code?
main()
{
 int c,d, *p1=&c,*p2=&d, x;
c =10,d =4;
x = –3* – *p2 / *p1 + 5;
printf(“%d ”,x);
}
A) 6
B) Invalid syntax because / * is used for comments.
C) 8
D) Invalid syntax because three binary operators can’t be together in an expression.

1.4 Which of the following is a wrong pointer declaration?
A) int *int(a);
B) int *x, *y;
C) float *aptr;
D) int *x, float *y;

1.3 *ptr ++ is equivalent to
A) ptr++
B) *ptr
C) ++ptr
D) ++*ptr



1.2 Which of the following expression is equivalent to ++*ptr?
A) (*ptr)++
B) ++*(ptr)
C) (ptr)*++
D) (ptr)++*

3. Find output
#include<stdio.h>
                                  int main()
                                  {
                                  char p[]="%d\n";
                                  p[1]='c';
                                  printf(p,65);
                                  int k=40,*a;
                                  a=&k;
                                  (*a)++;k++;
        printf("%d",k);

                                  return 0;
                                  }

4. find output
char a[] = "Hello", *p = a;
while (*p != '\0')
 printf("%s\n", p++);


True false
1.       If p is a pointer then the expression p = p + 1; adds 1 to the value of p regardless of p's type.
2.       If char *p = "Structured Programming", then p[5] is 'c'.
3.       NULL pointer points the base address of segment.
4.       Size of a pointer is equal to the data type it points to.

Fill in the blanks
1)       
header
2)       
pointer
3)       
external
4)       
Free()
5)       
garbage
6)       
void
7)       
pointer
8)       
error
9)       
header
10)    
Register

1.       ________ is a variable which holds the address of another variable.
2.       A global variable is also known as ________ variable.
3.       ________ cannot be legitimately passed to a function.
4.       A pointer contains ________ until it is initialized.
5.       If a function return type is declared as ________ it cannot return any value.
6.       NULL macro is defined in ________ file.
7.       The ________ operator is used to get value at address stored in a pointer variable.
8.       A Register variable is expected to be placed in machine ________.
9.       If you try to multiply or add two pointers, it will result in ________.

Match the following

1.        
operator used to get value at address stored in a pointer
a)       
A macro that represent null pointer
2.        
int *mptr, m=25; mptr=&m performs
b)       
Increase or decrease of pointer value
3.        
Null pointer is
c)        
*
4.        
Size of a pointer in small memory model is
d)       
(*ptr)++
5.        
Null macros is
e)       
Initializes the pointer
6.        
pointer arithmetic refers to
f)        
2 byte
7.        
size of void pointer in byte
g)       
A pointer which does not point anywhere
8.        
++*ptr
h)       
4byte

Question
1. What is dangling pointer in C? What is wild pointer in C? Give example.
2. Write a C program to modify the constant variable. 
4 Assuming ip is a pointer; explain the function of following statements:
i) ip = ip + 5;
 ii) ip = ip – 10;
iii) ip –
 iv) *ip++
v) *ip –
5. Assume following code:
int dat = 100;
 int *var
var = &dat;
 Here dat is an integer variable and var is a pointer.
 Answer the output of the following statements, in this regards and explain your answer
 i) printf(“%d”, * var);
ii) printf(“%d”, (* var)++);
iii) printf(“%d”, var);
iv) printf(“%d”, -var);
6. The ‘*’ symbol is used for two different purposes in pointer data type. Explain them.
7. What is pointer? How is it initialized? What is indirection operator? What is the scale factor of a pointer? What is the size of a pointer variable?

37 . Do you think C language support ‘pointer to function’? Explain it by any example?

No comments:

Post a Comment

ch-12 File Handling

Mcq 1. What does fp point to in the program?   #include<stdio.h> int main() {   FILE *fp;   fp=fopen("trial",...