I have an int array and I need to find the number of elements in it. I know it has something to do with sizeof but I’m not sure how to use it exactly. example
int data2[]={a,b,c,d};
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
With an array you can do:
But this only works with arrays, and won’t work if you’ve passed the array to a function: at that point the array decays to a pointer, and so
sizeofwill return the size of the pointer.You’ll see this wrapped up in a macro: