A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

C program to count Array elements by using sizeof() operator
Q:

C program to count Array elements by using sizeof() operator

0

C program to count Array elements by using sizeof() operator

sizeof() operator returns the total number of size occupied by a variable, since array is also a variable, we can get the occupied size of array elements.

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to count total number of array elements in C

#include <stdio.h>
int main()
{
	int arr[]={10,20,30,40,50};
	int n;
	
	n=sizeof(arr)/sizeof(int);
	
	printf("Number of elemenets are: %d\n",n);
	
	return 0;
}

Output

Number of elemenets are: 5

Another method

We can divide the occupied size of all array elements by size of any one array element. Consider the following statement:

n=sizeof(arr)/sizeof(arr[0]);

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now