Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Sizeof Operator

Posted on 2007-10-11
6
Medium Priority
?
227 Views
Last Modified: 2010-04-15
char *p1;  // or int *p1 or long *p1 or double *p1
printf("\n Sizeof P1 :: %d \n", sizeof(p1));

O/p ::  I always get 4 bytes .. Why all the times it gives 4 bytes
0
Comment
Question by:gauravflame
  • 2
  • 2
  • 2
6 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 500 total points
ID: 20054979
apparently all pointers on your machine take 4 bytes.
did you want sizeof(*p1)?
0
 

Author Comment

by:gauravflame
ID: 20054994
I am here looking for concept ,why 4 bytes for char ,int or long? what is the theory ?

printf("\n Sizeof P1 :: %d \n", sizeof(p1));
0
 

Author Comment

by:gauravflame
ID: 20054996
I am  not looking for
sizeof(*p1)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 500 total points
ID: 20055017
>> I am here looking for concept ,why 4 bytes for char ,int or long? what is the theory ?

It's for bytes for a POINTER TO char, int and long. It's the pointer that is 4 bytes long, not the value that it's pointing to.

A pointer is basically a memory address, and your system seems to use 4-byte memory addresses.
0
 
LVL 85

Expert Comment

by:ozo
ID: 20055029
On many machines, chars, ints and longs share the same address space, so it could make sense for all pointers into that address space to be the same size.

There is also the requirement that
A pointer to void may be converted to or from a pointer to any incomplete or object
type. A pointer to any incomplete or object type may be converted to a pointer to void
and back again; the result shall compare equal to the original pointer.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 20055077
>> It's for bytes for a POINTER TO char, int and long.

That should have been 4 instead of for of course :

"It's 4 bytes for a POINTER TO char, int and long."
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Suggested Courses

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question