1. What is dangling pointer in c?
  2. What is wild pointer in c?
  3. What are merits and demerits of array in c?
  4. Do you know memory representation of int a = 7 ?
  5. What is and why array in c?
Asked in/Preparing for : CTS
Reputation : 346


2 Responds



Dangling pointer:
If any pointer is pointing the memory address of any variable but after some variable has deleted from that memory location while pointer is still pointing such memory location. Such pointer is known as dangling pointer and this problem is known as dangling pointer problem.
 
Dangling pointer Example :
 
#include<stdio.h>
 
int *call();

int main(){
     int *ptr;
     ptr=call();
     fflush(stdin);
     printf("%d",*ptr);
     return 0;
}

int * call(){
    int x=25;
    ++x;
    return &x;
}
 
 
Output: Garbage value
Admin Team



A pointer in c which has not been initialized is known as wild pointer.
Example:
 
int main(){
     int *ptr;
     printf("%un",ptr);
     printf("%d",*ptr);
     return 0;
}
 
Output: Any address
Garbage value
 
Here ptr is wild pointer because it has not been initialized. There is difference between the NULL pointer and wild pointer. Null pointer points the base address of segment while wild pointer doesn’t point any specific memory location.

merits and demerits of array in c
 
Merits:
  • We can easily access each element of array.
  • Not necessity to declare too many variables.
  • Array elements are stored in continuous memory location.

 
Demerit:
Wastage of memory space. We cannot change size of array at the run time.
It can store only similar type of data.

Memory representation of int a = 7:
 
signed int a=7; (In Turbo c compiler)
signed short int a=7 (Both turbo c and Linux gcc compiler)
 
Binary equivalent of data 7 in 16 bit: 00000000 00000111
Data bit: 0000000 00000111 (Take first 15 bit form right side)
 
Sign bit: 0 (Take leftmost one bit)
 
First eight bit of data bit from right side i.e. 00000111 will store in the leftmost byte from right to left side and rest seven bit of data bit i.e. 0000000 will store in rightmost byte from right to left side
 
 
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.