Use of diff pointers

C

Comp.Lang.c

Hello
Iam Niranjan... i have one small doubt.

void main()
{
int size;
size = sizeof(int *);
printf("\n size of int *------>%x"size);
size = sizeof(char *);
printf("\n size of char *------>%x"size);
size = sizeof(float *);
printf("\n size of float *------>%x"size);
}
here i got the same size for all three.
when all three taking the same size... why we need different type of
pointers..
plz clarify any one..
Thanking you
Niranjan
 
R

Richard Heathfield

Comp.Lang.c said:
Hello
Iam Niranjan... i have one small doubt.

void main()

Lesson 1: main returns int, not void.

When you have absorbed that lesson, let us know.
 
R

Richard Heathfield

Comp.Lang.c said:
whats the relation between main return type & pointers size...?

None whatsoever, because main always returns int.

When you understand that, we can move on to the next error in your example
program. There doesn't seem to be any point in teaching you new things
until you've understood the old things correctly. It would be like building
a house on sand.
 
K

Keith Thompson

Comp.Lang.c said:
Iam Niranjan... i have one small doubt.

I suggest you pick a name for yourself other than "Comp.Lang.c".
That's the name of the newsgroup; referring to yourself by the same
name is bound to cause confusion. (Using your own real name is
usually best, but some people choose to use pseudonyms.)
void main()

int main(void)
{
int size;
size = sizeof(int *);
printf("\n size of int *------>%x"size);
size = sizeof(char *);
printf("\n size of char *------>%x"size);
size = sizeof(float *);
printf("\n size of float *------>%x"size);
}
here i got the same size for all three.
when all three taking the same size... why we need different type of
pointers..

Because they point to different types.
 
T

Typhonike

they have fixed in size because pointer do not hold the variable's
itself they only hold the adresses.But it do not mean that one type of
pointer can hold all the types.we have to tell the compiler "this
pointer is use for this type of variable".the reason is c uses STRONGLY
TYPE CHECKING.we can't change variables types(of course pointers are
variavles too) during the run time and compile time.
 
C

Comp.Lang.c

Thanq Mr Keith Thompson.
its very very nice meeting you.
Thanking you, for your great Help.
Niranjan Podduturi.
+919849238297
 
C

Comp.Lang.c

Hello Sir,
I know ...
void main returns int.
Iam niranjan podduturi.
Iam from Hyderabad/India
Thanking you Sir.
Niranjan Podduturi
 
P

pete

Typhonike said:
they have fixed in size because pointer do not hold the variable's
itself they only hold the adresses.

No.

sizeof(int *), sizeof(char *), and sizeof(float *)
are all equal on OP's implementation through sheer coincidence.

The relative sizes of those types of pointers
is unspecified by the rules of the C programming language.
 
R

Roberto Waltman

Hello
Iam Niranjan... i have one small doubt.

void main()
{
int size;
size = sizeof(int *);
printf("\n size of int *------>%x"size);
size = sizeof(char *);
printf("\n size of char *------>%x"size);
size = sizeof(float *);
printf("\n size of float *------>%x"size);
}
here i got the same size for all three.
when all three taking the same size... why we need different type of
pointers..
plz clarify any one..
Thanking you
Niranjan

Try the following:

#include <stdio.h>
#include <stdlib.h>

int main()
{
int size;
int *p_to_int;
char *p_to_char;
short *p_to_short;
float *p_to_float;

size = sizeof(int *);
printf("size of int * ------->%x\n", size);

size = sizeof(char *);
printf("size of char * ------->%x\n", size);

size = sizeof(short *);
printf("size of short * ------>%x\n", size);

size = sizeof(float *);
printf("size of float * ------>%x\n", size);

size = sizeof(*p_to_int);
printf("size of *p_to_int ------>%x\n", size);

size = sizeof(*p_to_char);
printf("size of *p_to_char ------>%x\n", size);

size = sizeof(*p_to_short);
printf("size of *p_to_short ------>%x\n", size);

size = sizeof(*p_to_float);
printf("size of *p_to_float ------>%x\n", size);

return EXIT_SUCCESS;
}
 
R

Roberto Waltman

Roberto Waltman said:
Try the following:

Sorry, pasted the wrong file. I meant, try the following:

#include <stdio.h>
#include <stdlib.h>

int main()
{
int size;
char *p_to_char;
short *p_to_short;
int *p_to_int;
float *p_to_float;
double *p_to_double;

size = sizeof(p_to_char);
printf("size of p_to_char ------>%x\n", size);

size = sizeof(*p_to_char);
printf("size of *p_to_char ------>%x\n", size);

size = sizeof(p_to_short);
printf("size of p_to_short ------>%x\n", size);

size = sizeof(*p_to_short);
printf("size of *p_to_short ------>%x\n", size);

size = sizeof(p_to_int);
printf("size of p_to_int ------>%x\n", size);

size = sizeof(*p_to_int);
printf("size of *p_to_int ------>%x\n", size);

size = sizeof(p_to_float);
printf("size of p_to_float ------>%x\n", size);

size = sizeof(*p_to_float);
printf("size of *p_to_float ------>%x\n", size);

size = sizeof(p_to_double);
printf("size of p_to_double ------>%x\n", size);

size = sizeof(*p_to_double);
printf("size of *p_to_double ------>%x\n", size);

return EXIT_SUCCESS;
}
 
S

santosh

Comp.Lang.c said:
Hello Sir,
I know ...
void main returns int.
Iam niranjan podduturi.
Iam from Hyderabad/India
Thanking you Sir.
Niranjan Podduturi

I suppose you're another one of the frustrated BPO f**kers, trying to
troll on Usenet defaming your own country.

Go get a life. All you're managing to do is to appear a complete
jackass.
 
S

santosh

Typhonike said:
they have fixed in size because pointer do not hold the variable's
itself they only hold the adresses.

<OT>
Address sizes aren't fixed on all hardware. For example varying pointer
types were used under the real-mode x86 CPU, because of it's
segment:eek:ffset nature of memory addressing. The pointer sizes are the
same for the OP only because of his implementation. Though the OP
didn't mention it, it's very likely that his platform is a 32-bit x86
running under a protected mode OS with a 32-bit flat memory model. In
this case a single GP register can access the full range of a program's
address space and hence the C pointer types are constant in size.

The C standard does not specify the particular size or structure of
pointers. It's upto the implementor, who is in turn, dictated by the
nature of the hardware.
</OT>
 
S

santosh

Comp.Lang.c said:
Hello Sir,
I know ...

Quote context if you're serious about participating in this newsgroup.
Read the following:

<http://cfaj.freeshell.org/google/>
<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>
<http://www.safalra.com/special/googlegroupsreply/>
void main returns int.

Under a conforming implementation main() returns an int and only an int
at all times. void main() is invalid.
Iam niranjan podduturi.
Iam from Hyderabad/India

Who the hell cares what you're name is or where you stay. Confine your
posts to this group to ISO C.
Thanking you Sir.
Niranjan Podduturi

BTW, Usenet posts aren't letters.
 
K

Keith Thompson

santosh said:
Quote context if you're serious about participating in this newsgroup.
Read the following:

<http://cfaj.freeshell.org/google/>
<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>
<http://www.safalra.com/special/googlegroupsreply/>


Under a conforming implementation main() returns an int and only an int
at all times. void main() is invalid.

That's not *quite* true. The standard allows an implementation to
define other forms for main(), but only
int main(void)
and
int main(int argc, char **argv)
are guaranteed to be portable (for hosted implementations), and
there's practically never a good reason to use void main().
Who the hell cares what you're name is or where you stay. Confine your
posts to this group to ISO C.

Perhaps you could have expressed this with a bit more subtlety. The
OP needs to learn a few things about this newsgroup, and about Usenet
in general, but there's no need to be rude about it.
 
T

Tomás

Keith Thompson posted:
That's not *quite* true. The standard allows an implementation to
define other forms for main(), but only
int main(void)


We're getting into semantics here, but I don't consider:

int main()

to be different from:

int main(void)


Nor do I consider any of the following to be different:

signed main();
signed int main(void);
int main();
signed main(void);
signed int main();
int main(void);


-Tomás
 
K

Keith Thompson

Tomás said:
Keith Thompson posted:



We're getting into semantics here, but I don't consider:

int main()

to be different from:

int main(void)

They're different in a declaration (prototype), but the same in a
definition. But then, there's not much point in declaring a separate
prototype for main.
Nor do I consider any of the following to be different:

signed main();
signed int main(void);
int main();
signed main(void);
signed int main();
int main(void);

Right. I should have added the phrase "or equivalent". For example:

typedef int FOOBAR;
typedef char OCELOT;
FOOBAR main(FOOBAR lutefisk, OCELOT **uffda);

is also legal.
 
D

Dik T. Winter

> We're getting into semantics here, but I don't consider:
> int main()
> to be different from:
> int main(void)

Eh? See the difference when I write
a = main(1, 2);
this is valid for "int main()" but not for "int main(void)".
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top