Why don\'t we add null pointer at the end of array of integer?How can we calculate the length of array of integer?

Questions by gau_bhatnagar   answers by gau_bhatnagar

Showing Answers 1 - 15 of 15 Answers

venkatesh

  • Jan 5th, 2006
 

use strlen() function.

  Was this answer useful?  Yes

Anand P Mishra

  • Jan 15th, 2006
 

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

  Was this answer useful?  Yes

Rishi

  • Jan 25th, 2006
 

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

  Was this answer useful?  Yes

mef526

  • Feb 13th, 2006
 

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)

  Was this answer useful?  Yes

Sachidananda Patnik

  • Feb 18th, 2006
 

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++;

  Was this answer useful?  Yes

ali

  • Aug 2nd, 2007
 

The last character in strings is the null character '' and not the Null pointer.Please correct me if i am wrong.

  Was this answer useful?  Yes

No Ali null is not equal to '' it was nul.

NULL is a macro defined in for the null pointer. NUL is the name of the first character in the ASCII character set. It corresponds to a zero value. There's no standard macro NUL in C, but some people like to define it. The digit 0 corresponds to a value of 80, decimal. Don't confuse the digit 0 with the value of '' (NUL)! NULL can be defined as ((void*)0), NUL as ''.

  Was this answer useful?  Yes

In case of array of characters we need a null pointer because after we get the output we press the enter key which takes 1 ASCII character value and as a result we need the null character.
But in case of array of integers since the array is of int datatype, even if we press the enter key, the ASCII value of enter is not taken.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions