GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 415 of 453    Print  
What's the best way to declare and define global variables
What's the best way to declare and define global variables and functions?


  
Total Answers and Comments: 3 Last Update: June 21, 2008     Asked by: lakshmi5783 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: rimi.mnnit
 
If a program is in several source files,the best arrangement is to place each definition 
in some relevant source(.c) file, with an external declaration of function n variables in
 a seperate header file that is included by #include at the front of each source file..


Above answer was rated as good by the following members:
samcorp3, rajani_vaddepalli15
May 30, 2008 15:19:32   #1  
gunturi.prabhakar Member Since: May 2008   Contribution: 4    

RE: What's the best way to declare and define global variables
use extern storage class with that variable...
it can only make that as an external variable

 
Is this answer useful? Yes | No
May 30, 2008 15:32:53   #2  
rimi.mnnit Member Since: May 2008   Contribution: 5    

RE: What's the best way to declare and define global variables
If a program is in several source files the best arrangement is to place each definition 
in some relevant source(.c) file with an external declaration of function n variables in
a seperate header file that is included by #include at the front of each source file..

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 1Overall Rating: -N/A-    
June 20, 2008 10:28:50   #3  
rks_147 Member Since: June 2008   Contribution: 1    

RE: What's the best way to declare and define global variables
Best Way to represent a variable as global is Just define the variable at the initial or just below the headers files


For Example:-
#include<stdio.h>
#include<conio.h>
#define PIE 3.1415

void main()
{
body of program

}
getch()

where PIE is define globally.

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape