Possible Duplicate:
size of a datatype without using sizeof
This is question asked in a C interview I wanted to know what is the correct logic for this
If you are not having a sizeof operator in C, how will you get to know
the size of an int ?
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.
Use an array[*]:
Actually, due to a note in the section on pointer arithmetic, you don’t even need an array, because for the purposes of pointer arithmetic an object behaves like an array of size 1, and an off-the-end pointer is legal for an array:
[*] By which I mean, “a solution to the puzzle posed is to use an array”. Don’t actually use an array, use
sizeof!