How to find the size of an array in C and C++.
Let's first declare an array.
C++ Code
Size of an array is 6.
Let's first declare an array.
int arr[]={4,2,3,1,6,7}; /* Take the memory allocated by whole array divided by the memory allocated of a single element in an array. */ int len = sizeof(arr)/sizeof(arr[0]); // Now len contains the size of array.
How to Find size of Array in C, C++
#include<stdio.h> int main(){ int arr[]={4,2,3,1,6,7}; int len = sizeof(arr)/sizeof(arr[0]); printf("Size of an array is %d ",len); return 0; }C, C++ Interview Questions
C++ Code
#include <iostream> using namespace std; int main() { int arr[]={4,2,3,1,6,7}; int len = sizeof(arr)/sizeof(arr[0]); cout<<"Size of an array is " <<len; return 0; }Output :
Size of an array is 6.
No comments:
Post a Comment