How do I get the size of a pointer in C using sizeof? I want to malloc some memory to store a pointer (not the value being pointed to).
How do I get the size of a pointer in C using sizeof ?
Share
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.
Given an arbitrary type (I’ve chosen
charhere, but that is for sake of concrete example):You can use either of these expressions:
Leading to a
malloc()call such as:The last version has some benefits in that if the type of
ppcchanges, the expression still allocates the correct space.