R
raghu
look at the following code
#include <stdio.h>
int * get_number(int i);
main()
{
int *krrk[5];
int i = 0;
printf(" testing the address of a variable in the function\n i
address in main %u\n", &i);
krrk = get_number(i);
printf("for i = %d address %u and its contents %d\n", i, krrk,
*krrk);
for(i = 1; i < 5; i++)
{
krrk = get_number(i);
printf("for i = %d address %u and its contents %d\n", i, krrk,
*krrk);
printf("for i - 1 = %d address %u and its contents %d\n", i - 1,
krrk[i - 1], *krrk[i - 1]);
}
for( i = 0 ; i < 5; i++)
{
printf(" for i = %d address of %d is %u\n", i, *krrk, krrk);
}
}
int * get_number(int i)
{
return &i;
}
testing the address of a variable in the function
i address i nmain 2280636
for i = 0 address 2280576 and its contents 0
for i = 1 address 2280576 and its contents 1
for i -1 = 0 address 2280576 and its contents 4202572
for i = 2 address 2280576 and its contents 2
for i -1 = 1 address 2280576 and its contents 4202572
for i = 3 address 2280576 and its contents 3
for i -1 = 2 address 2280576 and its contents 4202572
for i = 4 address 2280576 and its contents 4
for i -1 = 3 address 2280576 and its contents 4202572
for i = 0 address of 4202616 is 2280576
for i = 1 address of 4202664 is 2280576
for i = 2 address of 4202664 is 2280576
for i = 3 address of 4202664 is 2280576
for i = 4 address of 4202664 is 2280576
Here I am returning a local variable of a function And capturing its
address in a array of pointers. In the main function for the first
access its giving the correct answer but for the second access its
giving wrong(what ever order either 'for i = 1..' or 'for i - 1 =
0..'). why it behaves like so?
If we use msgQCreate in the same fashion its working fine why?
awaitng for ur reply.
-Raghu
#include <stdio.h>
int * get_number(int i);
main()
{
int *krrk[5];
int i = 0;
printf(" testing the address of a variable in the function\n i
address in main %u\n", &i);
krrk = get_number(i);
printf("for i = %d address %u and its contents %d\n", i, krrk,
*krrk);
for(i = 1; i < 5; i++)
{
krrk = get_number(i);
printf("for i = %d address %u and its contents %d\n", i, krrk,
*krrk);
printf("for i - 1 = %d address %u and its contents %d\n", i - 1,
krrk[i - 1], *krrk[i - 1]);
}
for( i = 0 ; i < 5; i++)
{
printf(" for i = %d address of %d is %u\n", i, *krrk, krrk);
}
}
int * get_number(int i)
{
return &i;
}
testing the address of a variable in the function
i address i nmain 2280636
for i = 0 address 2280576 and its contents 0
for i = 1 address 2280576 and its contents 1
for i -1 = 0 address 2280576 and its contents 4202572
for i = 2 address 2280576 and its contents 2
for i -1 = 1 address 2280576 and its contents 4202572
for i = 3 address 2280576 and its contents 3
for i -1 = 2 address 2280576 and its contents 4202572
for i = 4 address 2280576 and its contents 4
for i -1 = 3 address 2280576 and its contents 4202572
for i = 0 address of 4202616 is 2280576
for i = 1 address of 4202664 is 2280576
for i = 2 address of 4202664 is 2280576
for i = 3 address of 4202664 is 2280576
for i = 4 address of 4202664 is 2280576
Here I am returning a local variable of a function And capturing its
address in a array of pointers. In the main function for the first
access its giving the correct answer but for the second access its
giving wrong(what ever order either 'for i = 1..' or 'for i - 1 =
0..'). why it behaves like so?
If we use msgQCreate in the same fashion its working fine why?
awaitng for ur reply.
-Raghu