variable scope

Discussion in 'C' started by mundrapiyush, Mar 28, 2008.

  1. mundrapiyush

    mundrapiyush New Member

    Joined:
    Mar 28, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I was just playing around with pointers. In the following code what i feel is once check is executed the variable i and j must get killed as soon as the function returns. So actually we should not be able to collect it in the variable 'c' inside the main. Guys please tell whether my justification is right or wrong ?
    Code:
    [I]int* check(int,int);
    
    void main()
    {
    	int *c;
    	c = check(10,20);
    	printf("\nc = %d",*c);
    }
    
    int* check(int i, int j)
    {
    	int *p, *q;
    	p = &i;
    	q = &j;
    	if(i >= 45)
    		return(p);
    	else
    		return(q);
    }[/I]
     
    Last edited by a moderator: Mar 29, 2008

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice