Programming in C Essays

Submitted By mgmanoj
Words: 1415
Pages: 6

October 2001 1. How character constant is expressed in C? How does it differ from string constant?
A character constant is a single character enclosed in apostrophes. Example: ‘B’ ‘A’ ‘C’
A string constant consists of any number of consecutive characters enclosed in double quotation marks. Example: “Chennai” “Birmingham”

2. How comma operators are useful in for statements. 3. Write a note on recursion.
Recursion is a process by which is a function calls itself repeatedly until some specified condition has been satisfied. In the recursive process, the action of each process linked to the results of the next process as chain. In order to solve a problem recursively, two conditions must be satisfied. First the problem must be written in a recursive form and second, the problem statement must include a stopping condition. When a recursive function is executed, it calls the same function from one place second time, the second call can again call the function and so on until the termination condition is encountered. Before moving to the next call, the set of local variables related to the current process is pushed in a stack and a different set of variables will be created for the next call. When encountering the termination condition the control returns from the pass to the previous call and the same process is repeated again and again. While returning to the previous call the set of local variables stored in the stack is popped to continue the execution. 4. What do you mean by Global variables? How does it differ from static variables?
Global variables are defined at the beginning of the program before main function. Declaration is located outside the scope of the any of the functions making up the program. A global variable can only be used in an executable statement after it has been declared. An alteration in the value of a global variable within a given function is carried over into all other parts of the program. Static variables are local in scope to their module in which they are defined, but life is throughout the program. Value of global variable can be changed by any function while value of static is changed by defining function only. A static variable inside a function cannot be called from outside of the function but is alive and exist in memory. The next time this function is entered the same chunk of memory would be accessed now retaining the old value and no new memory is allocated this time for the variable like other variables in the function. 5. What values are automatically assigned to those array elements not explicitly initialized?
When array is declared and not explicitly initialized all the elements will have garbage values. This so happens because the storage class of this array is assumed to be auto. 6. What is a pointer? How it is initialized?
A pointer is a derived data type. A pointer is a variable that represents the location of a data item rather than the value of the data item. Within a variable declaration, a pointer variable can be initialized by assigning it the address of another variable. The variable whose address is assigned to the pointer variable must have been declared earlier in the program.
Example: float u, v; float *pv = &v;

When a pointer variable is declared, the variable must be preceded by an asterisk. Asterisk identifies that the variable is a pointer.

7. What is meant by nested structure?
When a structure is used within a structure is called nested structure.
Example : Struct stud_Res { int rno; char nm[50]; char std[10]; struct stud_subj { char subjnm[30]; int marks; }subj;
In above example, the structure stud_Res consists of stud_subj which itself is a structure with two members. Structure stud_Res is called as 'outer structure' while stud_subj is called as 'inner structure.' Internal structure member can be called as result.subj.marks. 8. What is the use of