Welcome Guest! To enable all features please Register.

Notification

Icon
Error

New Topic Post Reply
C/++ same name variable in two functions quesiton help?
Guest
#1 Posted : Tuesday, October 26, 2010 8:15:44 AM(UTC)
Rank: Guest

Joined: 12/12/2009(UTC)
Posts: 443
Points: 1,361
In C, if you have 2 functions and each declares a variable with the same name what will happen?

Wouldnt the program just crash? i dunno.. please enlighten me?
Thanks
Sponsor

Guest
#2 Posted : Tuesday, October 26, 2010 8:28:01 AM(UTC)
Rank: Guest

Joined: 12/12/2009(UTC)
Posts: 443
Points: 1,361
All variables in C/C++ have a scope. In your case, the variables are local in scope of their respective functions.
Hence, they do not create any problem for each other.

If you declare two variables with same name in same fucntions, then there would an error as both variables would be in same scope with same name which is not allowed in C/C++
Quick Reply Show Quick Reply
Users browsing this topic
Guest
New Topic Post Reply
Forum Jump  
You can post new topics in this forum.
You can reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.