1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

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