GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 187 of 436    Print  
Why don\'t we add null pointer at the end of array of integer?How can we calculate the length of array of integer?

  
Total Answers and Comments: 7 Last Update: August 02, 2007     Asked by: gau_bhatnagar 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
January 05, 2006 09:05:02   #1  
venkatesh        

RE: Why don't we add null pointer at the end of array...
use strlen() function.
 
Is this answer useful? Yes | No
January 15, 2006 06:20:06   #2  
Anand P Mishra        

RE: Why don't we add null pointer at the end of array...
In C there is no provision to specify the upper bound sp array does not perfofm upper bound checking and need not to sprcify the upper..NULL check
 
Is this answer useful? Yes | No
January 23, 2006 06:38:03   #3  
prathibhagb Member Since: December 2005   Contribution: 4    

RE: Why don't we add null pointer at the end of array...

we can calculate the length of an integer array by the following code

int array = {1,3,45,6,56};

size = sizeof(array)/sizeof(int);


 
Is this answer useful? Yes | No
January 25, 2006 00:28:41   #4  
Rishi        

RE: Why don't we add null pointer at the end of array...

Hi ,

# include < stdio.h >
# include < conio.h >


void accstrn();
int a [30];   // its a predefined array of 30 allocations.
int  c ;                // counter variable.
void main()

{

 clrscr();

 accstrn();

 printf ( " The length of the Int Array is %d ",c);
 
 getch();


}


void accstrn()
{
 

  for ( int i=0 ; i < 30 ; ++i )
 {
  scanf (" % d ", & a[i]);
  
  if ( a[i] != 0 )
 
  {
 
    c = i;
   
   accstrn ();
  }
  else
  {
   

   return (c);
  }
 }
}

Regards,

Rishi


 
Is this answer useful? Yes | No
February 13, 2006 10:49:52   #5  
mef526 Member Since: February 2006   Contribution: 13    

RE: Why don't we add null pointer at the end of array...

NULL is never added to any array since NULL is a pointer value. Typically it is

#define NULL (void*(0))

THere is no way to get the size of an array unless it is statically allocated and the header that includes it defines the size or it is in the same module.

HEADER.H

extern int a[];

CCODE.C

int n = sizeof(a);  // Returns n = 4 (pointer size)

int b[10];

int m= sizeof(b); // Returns m= 10 * sizeof(int)


 
Is this answer useful? Yes | No
February 18, 2006 06:07:21   #6  
Sachidananda Patnik        

RE: Why don't we add null pointer at the end of array...

Null Pointer is used for the recogniation of the strings. But to calculate the length of the integer array, simpaly we can use a clunter while inserting the value to the array and we can calculate the lenght.

Suppose

int *arr,i;

scanf("%d",&arr[i]);

counter++;


 
Is this answer useful? Yes | No
August 02, 2007 10:45:46   #7  
ali        

RE: Why don't we add null pointer at the end of array...
The last character in strings is the null character '' and not the Null pointer.Please correct me if i am wrong.
 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape