Skip to main content

Posts

Showing posts from November, 2013

How to find size of array in C/C++ program

#include<iostream> using namespace std; int main() { int a[]={1,2,3,4,5,6,7}; int size; size=sizeof(a)/sizeof(a[0]); cout<<"sizeof a"<<size<<"\n"; system("PAUSE"); return 0; } Output: sizeof a  7 Note : sizeof(a) returns size in bytes and sizeof(a)/sizeof(a[0]) returns number of elements in an array.