facing a issue in c code while using global variable
Posted: Sun Sep 11, 2016 4:09 pm
i am facing a problem while using globale variable in c language
here is code this is not orignale code but logic is same.
int number;/*Global Variable*/
int main()
{
number=10;
}
fun1()
{
number=20;
}
fun2()
{
number=30;
}
here is output
C:\Windows\system32\cmd.exe /C C:/TDM-GCC-64/bin/mingw32-make.exe -j4 SHELL=cmd.exe -e -f Makefile
"----------Building project:[ global_varibale - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'C:/Users/devilgeek/Dropbox/My Workspace/Myworkspace/global_varibale'
mingw32-make.exe[1]: Leaving directory 'C:/Users/devilgeek/Dropbox/My Workspace/Myworkspace/global_varibale'
mingw32-make.exe[1]: Entering directory 'C:/Users/devilgeek/Dropbox/My Workspace/Myworkspace/global_varibale'
C:/TDM-GCC-64/bin/gcc.exe -c "C:/Users/devilgeek/Dropbox/My Workspace/Myworkspace/global_varibale/main.c" -g -O0 -Wall -o ./Debug/main.c.o -I. -I.
C:/Users/devilgeek/Dropbox/My Workspace/Myworkspace/global_varibale/main.c:6:1: warning: return type defaults to 'int' [-Wimplicit-int]
fun1()
^
C:/Users/devilgeek/Dropbox/My Workspace/Myworkspace/global_varibale/main.c:10:1: warning: return type defaults to 'int' [-Wimplicit-int]
fun2()
^
C:/Users/devilgeek/Dropbox/My Workspace/Myworkspace/global_varibale/main.c: In function 'fun1':
C:/Users/devilgeek/Dropbox/My Workspace/Myworkspace/global_varibale/main.c:9:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
C:/Users/devilgeek/Dropbox/My Workspace/Myworkspace/global_varibale/main.c: In function 'fun2':
C:/Users/devilgeek/Dropbox/My Workspace/Myworkspace/global_varibale/main.c:13:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
C:/TDM-GCC-64/bin/g++.exe -o ./Debug/global_varibale @"global_varibale.txt" -L.
mingw32-make.exe[1]: Leaving directory 'C:/Users/devilgeek/Dropbox/My Workspace/Myworkspace/global_varibale'
====0 errors, 4 warnings====
whereas i took this example from ANSI C and in my linux terminal this programme is working correctly.
here is code this is not orignale code but logic is same.
int number;/*Global Variable*/
int main()
{
number=10;
}
fun1()
{
number=20;
}
fun2()
{
number=30;
}
here is output
C:\Windows\system32\cmd.exe /C C:/TDM-GCC-64/bin/mingw32-make.exe -j4 SHELL=cmd.exe -e -f Makefile
"----------Building project:[ global_varibale - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'C:/Users/devilgeek/Dropbox/My Workspace/Myworkspace/global_varibale'
mingw32-make.exe[1]: Leaving directory 'C:/Users/devilgeek/Dropbox/My Workspace/Myworkspace/global_varibale'
mingw32-make.exe[1]: Entering directory 'C:/Users/devilgeek/Dropbox/My Workspace/Myworkspace/global_varibale'
C:/TDM-GCC-64/bin/gcc.exe -c "C:/Users/devilgeek/Dropbox/My Workspace/Myworkspace/global_varibale/main.c" -g -O0 -Wall -o ./Debug/main.c.o -I. -I.
C:/Users/devilgeek/Dropbox/My Workspace/Myworkspace/global_varibale/main.c:6:1: warning: return type defaults to 'int' [-Wimplicit-int]
fun1()
^
C:/Users/devilgeek/Dropbox/My Workspace/Myworkspace/global_varibale/main.c:10:1: warning: return type defaults to 'int' [-Wimplicit-int]
fun2()
^
C:/Users/devilgeek/Dropbox/My Workspace/Myworkspace/global_varibale/main.c: In function 'fun1':
C:/Users/devilgeek/Dropbox/My Workspace/Myworkspace/global_varibale/main.c:9:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
C:/Users/devilgeek/Dropbox/My Workspace/Myworkspace/global_varibale/main.c: In function 'fun2':
C:/Users/devilgeek/Dropbox/My Workspace/Myworkspace/global_varibale/main.c:13:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
C:/TDM-GCC-64/bin/g++.exe -o ./Debug/global_varibale @"global_varibale.txt" -L.
mingw32-make.exe[1]: Leaving directory 'C:/Users/devilgeek/Dropbox/My Workspace/Myworkspace/global_varibale'
====0 errors, 4 warnings====
whereas i took this example from ANSI C and in my linux terminal this programme is working correctly.