English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

when *a=1 and integer in c programing..

2006-11-01 03:16:52 · 2 answers · asked by ensiyeh r 1 in Computers & Internet Programming & Design

2 answers

make sure 'a' is defined as a pointer to another variable you've declared. like:

int b = 1;
int* a = &b;

Otherwise, if you simply declare
int* a;
*a = 1;

..then you have reserved memory for an address, but not for the contents. 'a' is pointing to a pseudo-random place in memory.

Secondly, printf() of 'a' should return the address you've reserved. printf() of '*a' should return the 1 as you're expecting. The most likely reason you're not seeing this is because 'a' is set to (1) - which means it is not a valid pointer. This can be caused by some compilers in a DEBUG build when a variable goes out of scope. As in:

int* a;
{
int b = 1;
a = &b;
}
// 'b' is now out of scope - some compilers will change memory to indicate this during a debug build. *a is now (0) !

Hope that helps.

2006-11-01 04:18:30 · answer #1 · answered by WickedSmaht 3 · 2 0

it is wrong output ,
your output should be
value of 'a' and , value at 'a'
ie. (some memory address) , 1

recheck your code

2006-11-01 11:31:35 · answer #2 · answered by RAJWANT M 1 · 0 0

fedest.com, questions and answers