What�s the best way to declare and define global variables? ,Java, C ,C++, ASP, ASP.net C# ,Struts ,Questions & Answer, Struts2, Ajax, Hibernate, Swing ,JSP , Servlet, J2EE ,Core Java ,Stping, VC++, HTML, DHTML, JAVASCRIPT, VB ,CSS, interview ,questions, and answers, for,experienced, and fresher
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. though there can be many "declarations" of a single "global" variable or function, there must be exactly one "definition". If a program is in several source files,the best arrangement is to place each definition 
in some relevant source 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.

More interview questions and answers

main() { struct date; struct student { char name[30]; struct date dob; }stud; struct date { int day,month,year; }; scanf("%s%d%d%d", stud.rollno, &student.dob.day, &student.dob.month, &student.dob.year); }

There were 10 records stored in "somefile.dat" but the following program printed 11 names. What went wrong? void main() { struct student { char name[30], rollno[6]; }stud; FILE *fp = fopen("somefile.dat","r"); while(!feof(fp)) { fread(&stud, sizeof(stud), 1 , fp); puts(stud.name); } }

Is there any difference between the two declarations, 1. int foo(int *arr[]) and 2. int foo(int *arr[2])

What is the subtle error in the following code segment? void fun(int n, int arr[]) { int *p=0; int i=0; while(i++

What is wrong with the following code? int *foo() { int *s = malloc(sizeof(int)100); assert(s != NULL); return s; }

What is the hidden bug with the following statement?

What is the hidden bug with the following statement? assert(val++ != 0);

void main() { int *i = 0x400; // i points to the address 400 *i = 0; // set the value of memory location pointed by i; }

#define assert(cond) if(!(cond)) \(fprintf(stderr, "assertion failed: %s, file %s, line %d \n",#cond,\__FILE__,__LINE__), abort()) void main() { int i = 10; if(i==0) assert(i < 100); else printf("This statement becomes else for if in assert macro"); }

Is the following code legal? struct a { int x; struct a b; }

Is the following code legal? struct a { int x; struct a *b; }

Is the following code legal? typedef struct a { int x; aType *b; }aType

Is the following code legal? typedef struct a aType; struct a { int x; aType *b; };

Is the following code legal? void main() { typedef struct a aType; aType someVariable; struct a { int x; aType *b; }; }

void main() { printf("sizeof (void *) = %d \n", sizeof( void *)); printf("sizeof (int *) = %d \n", sizeof(int *)); printf("sizeof (double *) = %d \n", sizeof(double *)); printf("sizeof(struct unknown *) = %d \n", sizeof(struct unknown *)); }

char inputString[100] = {0}; To get string input from the keyboard which one of the following is better? 1) gets(inputString) 2) fgets(inputString, sizeof(inputString), fp)

Which version do you prefer of the following two, 1) printf("%s",str); // or the more curt one 2) printf(str)

What is Operator overloading?

What is the difference between run time binding and compile time binding?

What is Difference Between C/C++?

What is Difference Between C/C++

What will be the output of the following code? void main (){ int i = 0 , a[3] ; a[i] = i++; printf ("%d",a[i]) ; }

Why doesn't the following code give the desired result?

Why doesn't the following statement work? char str[ ] = "Hello" ; strcat ( str, '!' )

How do I know how many elements an array can hold?

How do I write code that reads data at memory location specified by segment and offset?

Is it possible to have Virtual Constructor? If yes, how? If not, Why not possible ?

What about Virtual Destructor?

What is problem with Runtime type identification?

How Virtual functions call up is maintained?

Can inline functions have a recursion?

How do you link a C++ program to C functions?

Explain the scope resolution operator?

How many ways are there to initialize an int with a constant?

What is the difference between a copy constructor and an overloaded assignment operator?

When should you use multiple inheritance?

What is a virtual destructor?

n a constructor throw a exception? How to handle the error when the constructor fails?

What are the debugging methods you use when came across a problem?

How the compilers arranges the various sections in the executable image?

Explain the ISA and HASA class relationships. How would you implement each in a class design?

When is a template a better solution than a base class?

How do you know that your class needs a virtual destructor?

What is the difference between new/delete and malloc/free?

What happens when a function throws an exception that was not specified by an exception specification for this function?

Can you think of a situation where your program would crash without reaching the breakball, which you set at the beginning of main()?

What issue do auto_ptr objects address?

Why do C++ compilers need name mangling?

Is there anything you can do in C++ that you cannot do in C?

How do you decide which integer type to use?

What�s the best way to declare and define global variables?

What does extern mean in a function declaration?

How do I declare an array of N pointers to functions returning pointers to functions returning pointers to characters?

Declare a void pointer.

What is 'this' pointer?

What is the mean of Manglic in C++?

What are the access privileges in C++?

Explain the scope resolution operator?

What is a modifier?

wat do you mean by accessor?

give me a diff b/e Template class and class Template?

What are the types of container classes?

When does a name clash occur?

What is an iterator class?

Define namespace.

What are proxy objects?

What is a node class?

What is stack unwinding?

What is class invariant?

Differentiate between the message and method.

What is a dangling pointer?

What is an incomplete type?

What is an Iterator class?

What is a nested class? Why can it be useful?

What is multiple inheritance(virtual inheritance)? What are its advantages and disadvantages?

Whit is the mean of precondition and post-condition to a member function.

What is inline function??

What is the use of class wizard?

What is the use of Microsoft foundation class library?

What is an orthogonal base class?

How can you catch all the exceptions without specifying individually?

What is the use of try block?

Give the name some pure object oriented languages.

What is mean of translation?

Write the different forms of throw?

What is the use of application wizard?

What are the basic segments of error handling code?

Give an example for asynchronous exceptions?

What is the use of export?

What is overflow error?

What is Memory alignment??

Define the generic programming?

Define the generic programming?

Define the parameterized macros?

What is function overloading and operator overloading?

What are the functions used to handle single character at a time?

What is the use of tellp ()?

What is the use of tellg ()?

whats the use of seekp() and seekg()?

What is the use of file pointers?

R4R provides free online tutolrails ,examples for Freshers and experts .We cover core java, tutorials, spring, Hibernate, python, struts, struts 2,c language, spring boot,PHP,MYSQL,C#,ASP.NET,WPF,WCF,Photoshop , JSP, programming, example, Interview questions and answer