- Joined
- Jan 21, 2010
- Messages
- 25,510
*a=15;
What does the * mean there?
This one because it doesn't change the value of actual argument.
But what if that function didn't change the value. Could you pass a constant value then?
*a=15;
This one because it doesn't change the value of actual argument.
I am passing address of variable a
#include<stdio.h>
void function(int a);
int main(void)
{
int z=10;
printf(" Before calling z = %d \n",z);
function(z);
printf("After calling z=%d \n",z);
return 0;
}
void function(int *a)
{
a*=15;
}
#include<stdio.h>
void function(int a);
int main(void)
{
int z=10;
printf(" Before calling z = %d \n",z);
function(z);
printf("After calling z=%d \n",z);
return 0;
}
void function(int *a)
{
a*=15;
}
During execution, what does a hold?
actual arguments is z=10; and formal arguments is a* = 15
I think during execution a will hold the actual value 10
int *a = 15 // we are declaring and assigning value 15 to pointer variable a //
Aren't they the same thing?
No. It can't hold 10, because a is not an integer variable
int *a = 15But we never do that, right?
There is no variable named 15.I think a is pointer variable and it store the address of variable 15
A pointer stores an address. This address need not necessarily be the address of a variable. It can also be the address of an I/O port, of a data structure or whatever.so pointer variable store only the address of another variable
Syntactically this is o.k. You can do this, if you like and if you understand the correct use of pointers. But typically there is simply no use for using this declaration. If you need to declare an integer, use "int a=15".int *a = 15
we don't write this because compiler assign address to pointer variable right