tiny C doubts..

is it valid
1.(Assigning a null value to reference)?
int **pt=NULL;
int &r=*pt;
(Indirectly assigning NULL ?? to &r)
2. int &f()
int y=10;
return y;

f()=30;//(what it does?)

int *pt=NULL;
this statement is perfectly valid and I am not sure about other statements.

1 Like

int *pt = NULL;//valid statement

Reason: pt is an integer pointer and NULL can be saved in them

int &r= ptr;//Invalid statement


  1. An integer’s address cannot be changed

  2. An integer whose address is NULL means there is no integer

  3. &r is to refer to address to address of r but = operator is not defined with it

int &f(){ int y = 10; return y;} main(){f()=30;cout << f();}//Valid statement

What will it do: Nothing will just print 10

what f() = 30 do?

Answer: suppose we declare an integer pointer(since return type of f() is int) as follows:

int *p = &f();

then *p will initially store address of f() and it will instead of calling pointeres will read as 10

f() = 30 will change it 30

but only values of pointers will be changed.

1 Like