1. What is NULL pointer?
  2. What is difference between pass by value and pass by reference?
  3. What is size of void pointer?
  4. What is difference between uninitialized pointer and null pointer?
  5. Can you read complex pointer declaration?
Asked in/Preparing for : CTS
Reputation : 346


2 Responds



1.
Literal meaning of NULL pointer is a pointer which is pointing to nothing. NULL pointer points the base address of segment.
 
Examples of NULL pointer:
1. int *ptr=(char *)0;
2. float *ptr=(float *)0;
3. char *ptr=(char *)0;
4. double *ptr=(double *)0;
5. char *ptr=’0’;
6. int *ptr=NULL;
 
 
What is meaning of NULL?
Answer:
 
NULL is macro constant which has been defined in the heard file stdio.h, alloc.h, mem.h, stddef.h and stdlib.h as
#define NULL 0

2.
In c we can pass the parameters in a function in two different ways.
(a)Pass by value: In this approach we pass copy of actual variables in function as a parameter. Hence any modification on parameters inside the function will not reflect in the actual variable. For example:
#include<stdio.h>

int main(){
     int a=5,b=10;
     swap(a,b);
     printf("%d %d",a,b);
     return 0;
}

void swap(int a,int b){
     int temp;
     temp =a;
     a=b;
     b=temp;
}

Output: 5 10
 
 
(b)Pass by reference: In this approach we pass memory address actual variables in function as a parameter. Hence any modification on parameters inside the function will reflect in the actual variable. For example:
#incude<stdio.h>
int main(){
     int a=5,b=10;
     swap(&a,&b);
     printf("%d %d",a,b);
     return 0;
}

void swap(int *a,int *b){
     int *temp;
     *temp =*a;
     *a=*b;
     *b=*temp;
}
 
Output: 10 5
 
Admin Team



3.
Size of any type of pointer in c is independent of data type which is pointer is pointing i.e. size of all type of pointer (near) in c is two byte either it is char pointer, double pointer, function pointer or null pointer. Void pointer is not exception of this rule and size of void pointer is also two byte.

4.
An uninitialized pointer is a pointer which points unknown memory location while null pointer is pointer which points a null value or base address of segment.
 
 
Admin Team



Written
Exam Questions
BLOG Posts
For study materials
Job Walk-In
Updates across India
Interview round
Questions
Interview or procedure
Experiences
Files
For study materials
Please LIKE our page to Get regular JOB WALK-IN UPDATES across India and STUDY MATERIALS on facebook news feed.