0 0 votes Can we declare a variable in main() which we will be using in another function? And why? Programming in C + – ranarajesh495 982 views answer comment Share Follow Print See all 7 Comments 7 7 Comments reply Magma commented Oct 10, 2018 reply Follow flag yes by passing the address of the variable 0 0 replyShare Dharmendra Lodhi commented Oct 10, 2018 reply Follow flag static and extern variable are used for global so we can use in another functions. 0 0 replyShare Magma commented Oct 10, 2018 i edited by Magma Oct 10, 2018 reply Follow flag void main () { int a = 12; Magma(&a); } void Magma (int *a) { (*a)++; } 0 0 replyShare Shaik Masthan commented Oct 10, 2018 reply Follow flag @Magma void main () { int a = 12; Magma(a); } void Magma (int &a) { a++; } is this valid in C? 0 0 replyShare Magma commented Oct 10, 2018 reply Follow flag What I know is yes but yeah I just run this code...and got error 0 0 replyShare ranarajesh495 commented Oct 10, 2018 reply Follow flag @magma Can you check the code by removing void in function return type or replace ' &a' with a int variable? I still can not figure out what is the meaning of &a argument 0 0 replyShare Shaik Masthan commented Oct 10, 2018 reply Follow flag you may use like void main () { int a = 12; Magma(&a); } void Magma (int *p) { (*p)++; // *p means a } 0 0 replyShare Please log in or register to add a comment.