A very naive question;
if declare a pointer
int *x.
then a int
int y.
now x points to an address.
and so do &y.
so can I say that x and &y are same type of containers?
Printable View
A very naive question;
if declare a pointer
int *x.
then a int
int y.
now x points to an address.
and so do &y.
so can I say that x and &y are same type of containers?
Well, they are both variables that are represented by a finite series of bits. Other than that, pointer types and integer types conceptually are completely different. I'm not sure what you mean by "containers."
When you refer to "x" that is basically the same thing as referring to "&y" assuming that you've coded x = &y at some point prior.
To make things clear. If there is a function with a syntax like:
function( char *x )
would it be same as
function( char y )
or function( &y ) be same as function( x ) ?
Yes, &y and x are the same type. Is that what you meant by container?
The prototype would be function(char *x) but the actual call would look like function(&y).
Quick example:
Code:
#include <stdio.h>
/* function expecting a pointer-to-integer */
void foo(int *x)
{
printf("%d\n", *x);
}
int main()
{
int *ptr;
int num = 100;
ptr = #
foo(&num);
foo(ptr);
}
Gotcha!! Thank you so much MacNilly !!!