Tell Me Something About Yourself - Interview Answers.

Try to introduce some of your most important employment-oriented skills as well as your education and accomplishments to the interviewer. Answer to this question is very important because it positions you for the rest of the interview. That's why this statement is often called the " Positioning Statement".

One should take the opportunity to show his/her communication skills by speaking clearly and concisely in an organized manner. Since there is no right or wrong answer for this question hence it is important to appear friendly.



YOUR ANSWERS CAN BE:

1) I am a person with strong interpersonal skills and have the ability to get along well with people. I enjoy challenges and looking for creative solutions to problems.

2) Besides the details given in my resume, I believe in character values, vision and action. I am quick in learning from mistakes. I am confident that the various tests that you have conducted will corroborate my competencies aptitude and right attitude for th…

Top 100 C Programming Interview Questions With Answers


1. Explain Various Classes Of Datatypes Of C?

Answer: Following are the major classes of data types in C language:
  • Primary Data Types: Also, known as fundamental/basic data types. All C compilers support four basic data types namely: integer(int), character(char), floating(float), and double precision floating point (double). Then there are extended data types such as long int, double int.
  • Derived Data Types: Also, known as secondary or user-defined data types. These data types, derived from basic data types, include arrays, pointer, structure, union, enum etc.

2. What Are Escape Sequences Characters? List Any Six Of Them.

Answer: The characters which when used with output functions like printf( ), putc(), put() etc. helps in formatting the output are known as Escape sequence character. The following is a list of six escape sequences.
  • \n Newline
  • \t Horizontal Tab
  • \v Vertical Tab
  • \b Backspace
  • \r Carriage Return
  • \\ Backslash

3. What Do You Mean By Underflow & Overflow Of Data?

Answer: When the value of the variable is either too long or too small for the data type to hold, the problem of data overflow or underflow occurs. The largest value that a variable can hold depends on the machine. Since floating point values are rounded off to the number of significant digits allowed, an overflow results in the largest possible real value whereas an underflow results in zero.

C does not provide any warning or indication of integer overflow; it simply gives erroneous result.


4. List Any Six Commonly Found Programming Errors In A C Program.

Answer: Six commonly found errors in a C program are:
  • Missing or misplaced; or }, missing return type for a procedure, missing or duplicate variable declaration.
  • Type mismatch between actual and formal parameters, type mismatch on assignment.
  • Forgetting the precedence of operators, declaration of function parameters.
  • Output errors means the program runs but produces an incorrect result. This indicates an error in the meaning of the program.
  • Exceptions that include division by zero, null pointer and out of memory.
  • Non-termination means the program does not terminate as expected, but continues running "forever."

5. Explain Divide & Conquer Strategy To Solve Any Problem.

Answer: The original problem is solved by repeatedly solving a divided sub-problem that is of smaller size and can be solved more efficiently. The problem is split into smaller sub-problems recursively until we eventually reach a stage where sub-problem is small enough to break further and can be solved easily. This strategy is called Divide and Conquer strategy.


Suppose a problem P is associated with a set S and an algorithm partitions S into smaller sets such that solution of the problem P is reduced to solution of its smaller sub-sets. Then this algorithm is called divide and conquer algorithm. For example, in searching for a key in an ordered list, the size of the list is halved after every search.


6. Differentiate Between White Box & Black Box Testing.

Answer: White box testing strategy deals with the internal logic and structure of the code. White box testing also known as glass, structural, open box or clear box testing, tests code written, branches, paths, statements and internal logic of the code etc. To implement white box testing, the tester must deal with the code and hence is needed to possess knowledge of coding and logic i.e. internal working of the code. White box test also needs the tester to consider the code and find out which unit/statement/chunk of the code is malfunctioning.

White box testing is applicable at unit, integration and system level however it is mainly done at unit level.

Black box testing Black-box test design treats the system as a "black-box", so it doesn't explicitly use knowledge of the internal structure. It takes an external perspective of the test object to derive test cases. These tests can be functional or non-functional, though usually functional. The test designer selects valid and invalid input and determines the correct output. There is no knowledge of the test object's internal structure.

This method of test design is applicable to all levels of software testing: unit, integration, functional testing, system and acceptance.




7. A Program Has Been Compiled & Linked Successfully. When You Run This Program, You Face One Or More Of The Following Situations
    • Program Executed, But No Output
    • It Produces Incorrect Answers
    • It Does Not Stop Running.

What Are The Possible Causes In Each Case & What Steps Would You Take To Correct Them?

Answer: A program has been compiled and linked successfully.
  • Program executed, but no output: This usually happens due to run time errors in the program like referencing an out-of-range array element or mismatch of data types.
  • It produces incorrect answers: Then there may be logical errors in the program like failure to consider a particular condition or incorrect translation of the algorithm into the program or incorrect order of evaluation of statements etc.
  • It does not stop running: This happens when we make use of correct syntax statement but incorrect logic like if(code=1) count++; Instead of using comparison operator we are using assignment which is syntactically correct so count++ is always executed resulting in infinite loop. Similar mistakes may occur in other control statements, such as for and while loop that causes infinite loops and does not stop running.

8. State The Differences Between Program Testing & Debugging.

Answer: Program Testing is the process of checking program, to verify that it satisfies its requirements and to detect errors. These errors can be of any type - Syntax errors, Run-time errors, Logical errors and Latent errors. Testing include necessary steps to detect all possible errors in the program. This can be done either at a module level known as unit testing or at program level known as integration testing.

Debugging is a methodical process of finding and reducing the number of bugs in a computer program making it behave as expected. One simple way to find the location of the error is to use print statement to display the values of the variables. Once the location of the error is found, the error is corrected and debugging statement may be removed.


9. State The Differences Between Top down & Bottom Up Approaches?

Answer: A top-down approach is essentially breaking down a system to gain insight into its compositional sub-systems. In a top-down approach an overview of the system is first formulated, specifying but not detailing any first-level subsystems. Each subsystem is then refined in greater detail, sometimes in many additional subsystem levels, until the entire specification is reduced to base elements. In short the top down approach means decomposing of the solution procedure into subtasks. This approach produces a readable and modular code that can be easily understood and maintained.

A bottom-up approach is essentially piecing together systems to give rise to grander systems, thus making the original systems sub-systems of the emergent system. In a bottom-up approach the individual base elements of the system are first specified in great detail. These elements are then linked together to form larger subsystems, which then in turn are linked, sometimes in many levels, until a complete top-level system is formed.


10. State The Differences Between Interpreted & Compiled Languages?

Answer: In interpreted languages, the instructions are executed immediately after parsing. Both tasks are performed by the interpreter. The code is saved in the same format that we entered. Interpreted languages include the MS-DOS Batch language (the OS itself is the interpreter), shell scripts in Unix/Linux systems, Java, Perl etc.

Advantages of interpreted languages include relative ease of programming and no linker requirement. Disadvantages include poor speed performance and that we do not generate an executable (and therefore distributable) program. The interpreter must be present on a system to run the program.

In compiled languages, the instructions into machine code and store them in a separate file for later execution. Many modern compilers can compile (parse) and execute in memory, giving the 'appearance' of an interpreted language.

However, the key difference is that parsing and execution occurs in two distinct steps. Examples of compiled languages include Visual Basic, C/C++, Delphi and many others. In a compiled environment, we have several separate files like: source code (the text instructions), object code (the parsed source code) and the executable (the linked object code).

There is definitely an increase in complexity in using compilers, but the key advantages are speed performance and that one can distribute stand-alone executables.


11. Briefly Explain What Do You Understand By Stepwise Refinement Of The Program?

Answer: The concept of "Stepwise Refinement" means to take an object and move it from a general perspective to a precise level of detail and this cannot be done in one jump but in steps. The number of steps needed to decompose an object into sufficient detail is ultimately based on the inherent nature of the object. "Stepwise Refinement" of program represents a "divide and conquer" approach to design.

In simple words, break a complex program into smaller, more manageable modules that can be reviewed and inspected before moving to the next level of detail. Stepwise refinement is a powerful paradigm for developing a complex program from a simple program by adding features incrementally.

Some of the steps taken for refinement of a program are:
  • Analysis of the algorithm used to develop the program, and analysis of various parts of the program and then making appropriate changes to improve the efficiency of the program.
  • Keep the program simple to improve memory efficiency.
  • Evaluation and incorporation of memory compression features.
  • Debugging and testing performed first to module level and then to interface level.
  • Take care of correct working and clarity while making it faster.


12. What Is The Difference Between Declaring A Variable & Defining A Variable?

Answer: The difference between declaring a variable and defining a variable is that while declaring a variable, the compiler verifies if the variable has been defined elsewhere but does not allocate memory for that variable. It is a kind of explicit declaration of a variable.

But while defining a variable, the compiler allocates specific memory for the variable and initializes the variable to some value. Normally, variables are declared after defining.


13. What Is Looping?

Answer: Loop is a control structure used to perform repetitive operation. Some programs involve repeating a set of instruction either a specified number of times or until a particular condition is met. This is done using a loop control structure. A program loop consists of two parts: Body of the loop and control statement. The control statement tests certain conditions and then decides repeated execution or termination of statements. Most real programs contain some construct that loops within the program, performing repetitive actions on a stream of data or a region of memory.


14. How Would You Distinguish Between Looping/Iteration & Recursion?

Answer: Some of the points that distinguish between recursion and looping/iteration are:
  • Recursive function is a function that is partially defined by itself whereas Iterative Instructions are loop based repetitions of a process.
  • Recursion Uses selection structure Iteration uses repetition structure Infinite recursion occurs if the recursion step does not reduce the problem in a manner that converges on some condition whereas an infinite loop occurs with iteration or looping if the loop-condition test never becomes false.
  • Recursion terminates when a base case is recognized whereas Iteration/looping terminates when the loop condition fails.
  • Recursion is usually slower then iteration/looping due to overhead of maintaining stack whereas Iteration/looping does not use stack so it's faster than recursion.
  • Recursion uses more memory than iteration/looping.
  • Infinite recursion can crash the system whereas infinite looping uses CPU cycles repeatedly.
  • Recursion makes code smaller whereas Iteration makes code longer.


15. What Is An Unsigned Integer Constant? What Is The Significance Of Declaring A Constant As Unsigned?

Answer: An integer constant is any number in the range -32768 to +32767, because an integer constant always occupies two bytes in memory and in two bytes we cannot store a number bigger than +32767 or smaller than -32768. Out of the two bytes to store an integer, the highest bit is used to store the sign of the integer.

This bit is 1 if the number is negative and 0 if number is positive. Unsigned integer constant is an integer constant which has the permissible range from 0 to 65536.

Significance of declaring a constant as unsigned almost doubles the size of the largest possible value. This happens because on declaring a constant as unsigned, the sixteenth bit is free and is not used to store the sign of the constant.


16. Differentiate Between Break & Continue Statement?

Answer: Two keywords that are very important to looping are break and continue. The break command will exit the most immediately surrounding loop regardless of what the conditions of the loop are. Break is useful if we want to exit a loop under special circumstances.

Continue is another keyword that controls the flow of loops. If we are executing a loop and hit a continue statement, the loop will stop its current iteration, update itself (in the case of for loops) and begin to execute again from the top.

Essentially, the continue statement is saying "this iteration of the loop is done; let's continue with the loop without executing whatever code comes after me."

The syntax of continue statement is simple continue;


17. Differentiate Between GoTo & Break Statement?

Answer: C support GoTo statement to branch unconditionally from one point to another in the program. The goto keyword is followed by a label, which is basically some identifier placed elsewhere in the program where the control is to be transferred.

During running of a program, the statement like "goto label1;" cause the flow of control to the statement immediately following the label "label1". We can have a forward jump or a backward jump.

#include <stdio.h >
void main()
{
  int attempt, number = 46;
  looping: /* a label */
    printf("Guess a number from 0-100\n");
  scanf("%d", & amp; attempt);
  if (number == attempt) {
    printf("You guessed correctly!\n\n");
  } else {
    printf("Let me ask again...\n\n");
    goto looping; /* Jump to the label*/
  }
  getch();
}

whereas Break is useful if we want to exit a loop under special circumstances.

#include <stdio.h>
void main()
{
  int a;
  printf("Pick a number from 1 to 4:\n");
  scanf("%d", & amp; a);
  switch (a) {
  case 1:
    printf("You chose number 1\n");
    break;
  case 2:
    printf("You chose number 2\n");
    break;
  default:
    printf("That's not 1,2,3 or 4!\n");
  }
  getch();
}


18. What Is The Purpose Of The Do-While Loop In C?

Answer: Do-while loop or post tested loop is the loop used when it is necessary to execute the loop at least once in the execution of the program. The syntax of the do-while loop is:

do
{
loop body
} while (condition);


19. What Is The Difference Between Uses Of  For & While Loops?

Answer: When a user wants to initialize, check condition and increment or decrement the value of a variable in a single statement, and using an iterative loop, then the loop used may be for loop.

When the user wants to initialize, check condition and increment or decrement value not using a single iterative loop, then he/she may use the while loop. Only one condition can be checked using the while loop.




20. What Is The Importance Or Purpose Of Main () Function?

Answer: main() is a special function used by C system to tell the computer where the program
starts.

The main() function in C is the most vital part of a program. The program execution occurs from the main() function. The main() function may contain any number of statements and they are sequentially executed. main() function can in turn call other functions.


21. Which Header File Is Used For Screen Handling Function?

Answer: The header file stdio.h contains definitions of constants, macros and types, along with
function declarations for standard I/O functions.



22. How Many Types Of Logical Operators Are There In 'C' Programming Language?

Answer: C allows usage of three logical operators:

For example:

(4 == 4) && (5!= 1) evaluates to True (1), because both operands are true.
(4 > 1) || (9 < 1) evaluates to True (1), because one operand is true (4 > 1).
!(5 == 4) evaluates to True (1), because the operand is false.


23. What Is A Constant Variable?

Answer: By default the value of any variable in C is not constant. Hence, to assign a variable with a constant value throughout the program, the variable can be made a constant variable. Constant variable are declared using the const keyword and they make execution faster than non-constant variables.


24. Define Static Variable?

Answer: A static variable is a variable which has been allocated statically. i.e., the life of the variable extends as long as the entire run of the program. Static variables are global variables and find wide use in programs. It is declared as:

static datatype variable;


25. What Is A Register Variable?

Answer: Register variables are special variants of automatic variables. Register variables are stored in processor registers. The system register provides a certain control of efficiency of the program when variables are declared as register variables.


26. Where Is An Auto Variable Stored?

Answer: An auto variable is stored in the computer’s main memory.


27. What Is Meant By Scope & Storage Allocation Of A Variable Or Function?

Answer: The scope of a variable is defined by the storage allocation of that variable. Storage allocation of a variable decides the memory part where storage space is allocated for a particular variable or function.


28. What Is The Scope & Storage Allocation Of Extern & Global Variables?

Answer: Extern variables are global variables. These variables belong to the external storage class and are stored in the system’s main memory. They are declared in a separate source file which could be outside the current program scope. The scope of these variables is global.

Global variables are variables declared above the main function. They are accessible throughout the program. They have 0 as the default value.


29. What Is The Scope & Storage Allocation Of Register?

Answer: Register variables are storage allocated in the CPU registers. Since they are stored in the CPU registers, their storage and accessibility is much easier and faster than other variables. The scope of register variables is local to the blocks in which they are defined.


30. What Is The Scope & Storage Allocation Of Static & Local Variables?

Answer: The storage allocation of static variables is done at the beginning of program execution. After the program terminates, the memory is reallocated. Scope of static variables is local to the block within which they are defined.



Local variables are variables defined within a function or program. Their default value is a garbage value and they are accessed only by the particular function or program.


31. Distinguish Between Automatic & Static Variables?

Answer: Differences between automatic & static variables are:
  • Automatic variables are declared inside a function in which they are to be utilized, that’s why referred as local or internal variables whereas Static variables may be declared internally or externally.

A variable declared inside a function without storage class specification by default is an automatic variable. However, we may use the keyword auto to declare it explicitly.
main()
{
auto int age;
}

whereas keyword static is used to declare a static variable.
Static int age;

  • Default initial value for an automatic variable is Garbage value whereas static variables have zero as default initial value.
  • Automatic variables are created when the function is called and destroyed on exit from the function whereas in case of internal static variable, the scope is local to the function in which defined while scope of external static variable is to all the functions defined in the program.
  • Value of automatic variable lasts till the control remains within the block in which defined whereas value of static variable persists between different function calls.


32. Differentiate Between Global/External & Local Variables?

Answer:  Differences between global/external & local variable are:
  • Global variables are declared outside of all functions or before main whereas Local variables are declared inside a function where it is to be used.
  • Global variables can be used in all the functions in the program whereas Local variables are not known to other function in the program. It is limited to a single function only.
  • Global variables need not be declared in other functions whereas Local variables are visible and meaningful inside the functions in which they are declared.

For example:

#include <stdio.h>
int m;
void main( )
{
int i;
…..
…..
Fun1();
}
Fun1( )
{
int j;
….
…..
}
Here m is a global variable, i is local variable local to main () and j is local variable local to Fun1().



33. What Do You Understand By Scope, Lifetime & Visibility Of The Variables?

Answer: The scope of a variable determines the region of the program in which it is known. An identifier's "visibility" determines the portions of the program in which it can be referenced—its "scope." An identifier is visible only in portions of a program encompassed by its "scope," which may be limited to the file, function or block in which it appears.

File Scope: The variables and functions with file scope appear outside any block or list of parameters and is accessible from any place in the translation unit after its declaration. Identifier names with file scope are often called "global" or "external." The scope of a global identifier begins at the point of its definition or declaration and terminates at the end of the translation unit. A function has file scope.

Function Scope: A label is the only kind of identifier that has function scope. A label is declared implicitly by its use in a statement. Label names must be unique within a function however a label having the same name in two different functions is allowed.

Block Scope: The variables with block scope appear inside a block or within the list of formal parameter declarations in a function definition. It is visible only from the point of its declaration or definition to the end of the block containing its declaration or definition.


34. What Is Meant By Identifiers? How Do Identifiers Differ From Keywords?

Answer: Each C word can be classified as either a keyword or an identifier. Identifiers refer to the names of variables, functions and arrays. These are user-defined names and consist of a sequence of letters and digits, with a letter as a first character. Both uppercase and lowercase can be used to form identifiers.

Maximum length of an identifier is 8 characters. Some compiler allows length upto 40 characters. Comma and blanks are not allowed. No special symbol except underscore is allowed in identifiers name.

All keywords have fixed meanings and these cannot be changed. Keywords are the basic building blocks for program statement. The keywords also known as reserved words cannot be used as variable names. There are 32 keywords available in C.


35. How Can Register Access Be Made Faster Than Memory Access?

Answer: A register access is much faster than a memory access, keeping the frequently accessed variables in the register will lead to faster execution of programs.


36. What Is The Use Of Enumerated Data Types In C?

Answer: The enumerated data types give an opportunity to invent our own data type and define
what value the variable of this data type can take.



37. Which Bitwise Operator Is Used For Checking Whether A Particular Bit Is ON Or OFF?

Answer: The bitwise AND operator is used for checking whether a particular bit is ON or OFF.


38. Which Bitwise Operator Is Used For Turning OFF A Particular Bit In A Number?

Answer: Bitwise AND operator (&) and one’s complement operator (~) are suitable for turning OFF a particular bit in a number.


39. What Are The Bitwise Logical Operators?

Answer: Operators that are used for manipulation of data at bit level are known as bitwise operator. Bitwise logical operator are binary operator and require two integer type operand. These work on their operand bit by bit starting from the least significant bit.

There are following three logical bitwise operators:
  • Bitwise AND(&)
  • Bitwise OR(|)
  • Bitwise exclusive OR(^)

40. What Is Equivalent Of Multiplying An Unsigned Int By 2: Left Shift Of Number By 1 Or Right Shift Of Number By1?

Answer: Left shifting of an unsigned integer is equivalent to multiplying an unsigned int by 2.

41. What Is Enumeration?

Answer: Enumeration is data type. In C++, the user can create user defined data types and define values using them. This helps to make the program more readable. Enumeration data types are defined in similar ways as structures.


42. What Is Enumeration Constant?

Answer: When an enumeration data type is defined, a set of identifiers are specified which the data enumeration represents. Such an identifier is called an enumeration constant.



43. What Is Static Memory & Dynamic Memory Allocation?

Answer: Compiler allocates memory space for a declared variable. By using the address of operator, the reserved address is obtained and this address is assigned to a pointer variable. This way of assigning pointer value to a pointer variable at compilation time is known as static memory allocation.

A dynamic memory allocation uses functions such as malloc() or calloc() to get memory dynamically. If these functions are used to get memory dynamically and the values returned by these function are assigned to pointer variables, such a way of allocating memory at run time is known as dynamic memory allocation.


44. What Is Dynamic Memory Allocation? Explain The Various Memory Allocation Function With Its Task.

Answer: The mechanism of allocating required amount of memory at run time is called dynamic allocation of memory. Sometimes it is required to allocate memory at runtime. When we declare array in any program, the compiler allocates memory to hold the array.

Now suppose the numbers of items are larger than the defined size then it is not possible to hold all the elements and if we define an array large enough and data to be stored is less, in that case the allocated memory is wasted leading to a need for dynamic memory allocation. In this mechanism, we use a pointer variable to which memory is allocated at run time.


45. What Are The Three Dynamic Memory Allocation Functions?

Answer: Three dynamic memory allocation functions are: malloc, calloc and free.


46. Explain The Various Memory Allocation Function With Its Task In C Programming.

Answer: The various memory allocation functions are described below:
  • malloc(): It is a memory allocation function that allocates requested size of bytes and returns a pointer to the first byte of the allocated space. The malloc function returns a pointer of type void so we can assign it to any type of pointer. It takes the following form:
ptr = (cast type *) malloc(byte-size);
where ptr is a pointer of type cast-type.

For example, the statement

x = (int *) malloc(10 *sizeof(int)) means that a memory space equivalent to 10 times the size of an int byte is reserved and the address of the first byte of memory allocated is assigned to the pointer x of int type.

The malloc function can also allocate space for complex data types such as structures. For example:
ptr= (struct student*) malloc(sizeof (struct student));
where ptr is a pointer of type struct student.
  • calloc(): It is another memory allocation function that allocates space for an array of elements, initializes them to zero and then returns a pointer to the memory. This function is normally used for requesting memory space at run time. While malloc allocates a single block of storage space, calloc allocates multiple block of storage, each of the same size, and then sets all bytes to zero. It takes the following form:
ptr = (cast type *) calloc(n,element-size);

This statement allocates contiguous space for n blocks, each of size element-size bytes.
  • realloc(): realloc is a memory allocation function that modifies the size of previously allocated space. Sometime it may happen that the allocated memory space is larger than what is required or it is less than what is required. In both cases, we can change the memory size already allocated with the help of the realloc function known as reallocation of memory. For example, if the original allocation is done by statement
ptr = malloc(size);

then reallocation is done by the statement

ptr = realloc(ptr,newsize); which will allocate a new memory space of size newsize to the pointer variable ptr and returns a pointer to the first byte of the new memory block.


47. What Are The Differences Between Malloc() & Calloc()?

Answer: Differences between malloc() and calloc() are:
  • The malloc() function is used to allocate memory space. It reserves a memory space of specified size and gives the starting address to pointer variable whereas calloc() function is used to allocate multiple blocks of memory. This has two arguments. The calloc() function is generally used for allocating the memory space for arrays and structures.
  • Malloc takes one argument Malloc(a);where a represents number of bytes whereas Calloc takes two arguments Calloc(b,c) where b is the no of object and c represents size of object.
  • Calloc initializes the contains of block of memory to zeros whereas memory allocated using malloc contains garbage values.
  • Memory allocated using Malloc malloc function is contiguous whereas memory allocated using calloc is not contiguous.


48. What Is The Purpose Of Realloc?

Answer: It increases or decreases the size of dynamically allocated array. The function realloc (ptr, n) uses two arguments. The first argument ptr is a pointer to a block of memory for which the size is to be altered.

The second argument specifies the new size. The size may be increased or decreased. If sufficient space is not available to the old region the function may create a new region.


49. What Is The Purpose Of The Free() Function?

Answer: For efficient use of memory space, the memory space that is not required should be released. The free() function achieves this.


50. How To Use Realloc() To Dynamically Increase Size Of An Already Allocated Array?

Answer: The function realloc() can be used to change the size of the memory block reserved for a particular object. This is known as reallocation of memory.

The function realloc() moves the content of old block into the new block and the data of the old block is not lost.


51. In Which Header File Are The Memory Management Functions Defined?

Answer: Memory management functions which are used for allocating and freeing memory during execution of a program. These functions are defined in stdlib.h.


52. How Much Maximum Memory Can Be Allocated In A Single Call To Malloc() ?

Answer: 64 KB


53. What Are The Differences Between Formal Arguments & Actual Arguments Of A Function?

Answer: Formal arguments are parameters or arguments in a function declaration. The scope of such arguments is local to the function definition. Any change made to the formal arguments will not be reflected back in the main program.

Actual arguments are arguments that are passed in a function call. Such arguments are defined inside the function body.



54. What Is Call By Value In Functions?

Answer: Arguments or parameters can be passed to the functions by call by value. In call by value, the values of the variables are passed to the functions. In this, values of variables are not affected by changing the vale of the formal parameter.


55. What Is Call By Reference In Functions?

Answer: In Call by reference method of passing arguments to functions, the addresses of the variables are passed. In this, values of variables are affected by changing the value of formal parameters.


56. What Is The Difference Between Call By Value & Call By Reference (Or Pass By Value Or Pass By Reference)?

Answer: Call by value means sending the values of the arguments- The value of each of the actual arguments in the calling function is copied into corresponding formal arguments of the called function. The changes made to the formal arguments have no effect on the values of actual arguments in the calling function. This technique of passing arguments is called call by value illustrated by swapv(int x, int y) function in the following example.

Call by reference means sending the addresses of the arguments - the addresses of actual arguments in the calling function are copied into formal arguments of the called function. Using these addresses we are actually working on actual argument so changes will be reflected in the calling function. This technique of passing arguments is called call by reference, illustrated by swapr(int *x,int *y) in following example.

Call by reference passes a pointer to the value. This allows the callee to modify the variable directly. Call by value gives a copy of the value to the callee. This allows the callee to modify the value without modifying the variable. (In other words, the callee simply cannot modify the variable, since it lacks a reference to it.)


57. Can You Pass A Variable Argument List To A Function At Run Time?

Answer: No, we can't.  Every actual argument list must be known at compile time. In that sense, it is not truly a variable argument list.


58. Explain The Need For User defined Functions Or The Advantages Of Functions?

Answer: The need for user-defined function:
  • A programmer may have a block of code that he has repeated n times throughout the program. A function to execute that code would save a great deal of space, and it would also make the program more readable.
  • It is easy to locate and isolate a faulty function. Having only one copy of the code makes it easier to make changes.
  • Another reason for functions is to break down a complex program into logical parts. For example, take a menu program that runs complex code when a menu choice is selected. The program would probably best be served by making functions for each of the actual menu choices, and then breaking down the complex tasks into smaller, more manageable tasks, which could be in their own functions. 
  • In this way, a program can be designed that makes sense when read. And has a structure that is easier to understand quickly. The worst programs usually only have the required function, main, and fill it with pages of jumbled code.
  • A function may be used by many other programs. A programmer can use already compiled function instead of starting over from scratch.


59. What Are Function Prototype?

Answer: It is a common practice that all the function programs are written after the main( ) function .when they are accessed in the main program, an error of prototype function is shown by the compiler. It means the computer has no reference about the programmer defined functions, as they are accessed before the definition.

To overcome this, i.e. to make the compiler aware that the declarations of the function referred at the calling point follow, a declaration is done in the beginning of the program immediately after the preprocessor statements. Such a declaration of function is called prototype declaration and the corresponding functions are called function prototypes.


#include <stdio.h>
int maximum(int x, int y);
main()
{
  int a, b, c;
  scanf(“ % d % d”, & amp; a, & amp; b);
  c = maximum(a, b);
  printf(“\n maximum number is: % d”, c);
}
int maximum(int x, int y)
{
  int z;
  z = (x & gt; = y) ? x : y;
  return (z);
}



60. What Is Recursion?

Answer: Recursion is the process of repeating items in a self-similar way. Same applies in programming languages as well where if a programming allows you to call a function inside the same function that is called recursive call of the function as follows:

void recursion()
{
recursion(); /* function calls itself */
}
int main()
{
recursion();
}

The C programming language supports recursion, i.e., a function to call itself. But while using
recursion, programmers need to be careful to define an exit condition from the function, otherwise
it will go in infinite loop.

Recursive function is very useful to solve many mathematical problems like to calculate factorial
of a number, generating Fibonacci series, etc.


61. A Recursive Procedure Should Have Two Properties. What Are They?

Answer: There are two important conditions that must be satisfied by any recursive procedure. They are:
  • There must be some base case where the condition end.
  • Each recursive call to the procedure involve a smaller case of the problem.

62. What Is Recursive Function?

Answer: A recursive function is a function in which the statement of the function within the function body, calls the same function. Such a function is also called circular definition.


63. For Implementing Recursive Function Which Data Structure Is Used Is?

Answer:  For implementing recursive function, stack is used as a data structure.


64. Which Data Structure Is Needed To Convert A Recursion To An Iterative Procedure?

Answer: The data structure needed to convert a recursion to an iterative procedure is stack


65. What Impact Would An Infinite Recursion Have On Run-Time Stack?

Answer: It would result in an overflow of run time stack.


66. Why Is The Reasoning Behind 'Recursive Procedures Are Implemented By Using Stack Data Structure'?

Answer: Recursive procedures are implemented by using stacks because stacks are LIFO data structure and we need this feature to store return addresses of various recursive calls in recursive procedures.


67. What Are The Differences Between Getchar() & Scanf() Functions For Reading Strings?

Answer: The getchar() function is used to get a character from the standard input device. While using the getchar() function, there is no need to hit the return key. It is used only with character data types and it can be used to get continuous stream of characters.

The scanf() function is used to get input from the standard input device. Here, return key should be typed after each input. It can be used for all data types but continuous stream of inputs is not facilitated.


68. Out Of The Functions fgets() & gets(), Which One Is Safer To Use & Why?

Answer: Out of fgets() and gets(), the safer one to use is fgets(). The reason is, gets(), after receiving a string from the input device, gets terminated only when the enter key is pressed. The string can be limitless and it may cause buffer overflow.


69. What Is The Difference Between The Functions strdup() & strcpy()?

Answer: The strdup() function is helpful in duplicating a string to a location decided by the function itself. Here the contents of a string is copied to a memory location and returns the address.

The strcpy() function copies a string to a position demanded by the user. The arguments of the function are the source string and the destination string.

70. Explain, In Brief The Purpose Of The Following String Handling Functions: 
  • strcat 
  • strcmp 
  • strcpy. Use Suitable Examples.

Answer:
  • strcat() Function concatenates two strings together and has the following form: strcat(string1,string2);
When this function is executed, string2 is appended to string1 by removing the null character at the end of string1. C permits nesting of strcat functions as strcat(strcat(string1,string2),string3);

  • strcmp() is the string comparison function defined in string.h header file. It has the following form:
int strcmp ( const char *s1, const char *s2 );
strcmp will accept two strings. It will return an integer. This integer will either be:
    • Negative if s1 is less than s2.
    • Zero if s1 and s2 are equal.
    • Positive if s1 is greater than s2.
Strcmp performs a case sensitive comparison; if the strings are the same except for a difference in case, then they're countered as being different. Strcmp also passes the address of the character array to the function to allow it to be accessed.

  • strcpy ( ) function is just like a string-assignment operator which take the following form:
char *strcpy ( char *dest, const char *src );

strcpy is short for string copy, which means it copies the entire contents of src into dest. The contents of dest after strcpy will be exactly the same as src such that strcmp ( dest, src ) will return 0.src may be a character array variable or a string constant.


71. What Is A Macro? How Is It Different From A C Variable Name? What Are The Advantages Of Using Macro Definitions In A Program?

Answer: A macro is a pre-processor directive which is a program that processes the source code before it passes through the compiler. These are placed in the source program before the main. To define a macro, # define statement is used.

This statement, also known as macro definition takes the following general form:
#define identifier string

The preprocessor replaces every occurrence of the identifier in the source code by the string. The preprocessor directive definition is not terminated by a semicolon. For example

#define COUNT 100
will replace all occurrences of COUNT with 100 in the whole program before compilation.


72. What Are Preprocessor Directives? List Three Types Of Them.

Answer: Preprocessor directives are the commands given to a program known as preprocessor that processes the source code before it passes through the compiler. Each of these preprocessor directives begins with a # symbol. These can be placed anywhere in the program but usually placed before main ( ) or at the beginning of the program.

Before the source code passes through the compiler, it is examined by the preprocessor for any directives. If there are any, appropriate action is taken and the source program is handed over to compiler. These directives can be divided into following three categories:
  • Macro substitution directives
  • File inclusion directives.
  • Compiler control directives.

73. Explain The New #pragma Directive?

Answer: #pragma is an implementation oriented directive that specifies various instructions to be given to the compiler.

#pragma name
causes compiler to perform "name"


74. Explain The New #error Directive?

Answer: #error is a preprocessor directive used to produce diagnostic messages during debugging.

#error message
causes the compiler to display the error message and terminate processing on encountering this directive.


75. What Are The Features Of C Preprocessor?

Answer: A preprocessor is a program that processes the source code before it passes through the compiler. It operates under the control of preprocessor directive. These are placed in the source program before the main.

To define a macro, # define statement is used. This statement, also known as macro definition takes the following general form:

#define identifier string

The preprocessor replaces every occurrence of the identifier in the source code by the string. The preprocessor directive definition is not terminated by a semicolon.

For example;
#define COUNT 100 will replace all occurrences of COUNT with 100 in the whole program before compilation. Similarly, we can define small functions with the help of macros.

For example, a macro defined as
#define SQUARE(x) (x*x) will calculate square of argument when it is called. This is called macro definition.


76. Give The Differences Between Macros & Functions?

Answer: A macro's definition is expanded into the code each time the macro is encountered in the source code. If your program invokes a macro 100 times, 100 copies of the expanded macro code are in the final program. In contrast, a function's code exists only as a single copy. Therefore, in terms of program size, the better choice is a true function.

When a program calls a function, a certain amount of processing overhead is required in order to pass execution to the function code and then return execution to the calling program. There is no processing overhead in "calling" a macro. In terms of speed, a macro has the advantage.


77. What Is The Difference Between The Following Directives: #include <filename> & #include "filename"?

Answer: Difference between both the syntax is:
  • #include "filename": The search for the file is made first in the current directory and then in the standard directories as mentioned in the include search path.
  • #include <filename>: This command would look for the file in the standard list of directories.


Both directives cause the entire contents of filename to be inserted into the source code at that point in the program.


78. How Is Searching In an Arraylist Carried Out?

Answer: For searching an element in an array list, first we traverse the array list and with traversing, we compare each element of array with the given element.


79. Where Can An Element Are Inserted In An Array List?

Answer: Insertion into an arraylist is possible in three ways:
  • Insertion at the beginning.
  • Insertion at the end.
  • Insertion in between.

80. How Is Deletion In An Array List Carried Out?

Answer: Deletion from an array list is possible in three ways:
  • Deletion of the first element.
  • Deletion of the last element.
  • Deletion in between.

81. What Are The Advantages Of Array Lists?

Answer: The major advantage of the array list is that we can easily compute the address of the array through index and we can also access the array element through the index.


82. What Are The Disadvantages Of An Array List?

Answer: The disadvantage of an array list is that we have to keep the total number of elements and array size. We cannot take elements more than array size because array size is fixed. It requires much processing in insertion and deletion of shifting of array elements.


83. What Is The Maximum Number Of Dimensions An Array Can Have In C?

Answer: C allows arrays of three or more dimensions. The exact limit is determined by the
compiler.


84. What Is The Size Of Array int a[5]={1,2} ?

Answer: The size of int array is 2*5=10 bytes as int takes 2 bytes of storage.


85. To Declare An Array S That Holds A 5 Character String, What Would You Write?

Answer: A string is nothing but a char array. It should be declared as char S[5]


86. Why ‘&’ Operator Is Not Used With Array Names In A scanf Statement?

Answer: In scanf() statement, the "address of" operator (&) either on the element of the array (e.g. marks[i]) or on the variables (e.g &rate) are used. In doing so, the address of this particular array element is passed to the scanf() function, rather than its value; which is what scanf() requires. BUT many times, the address of zeroth element (also called as base address) can be passed by just passing the name of the array.


87. What are Multidimensional Arrays?

Answer: Multidimensional arrays can be described as "arrays of arrays". For example, a bi-dimensional array can be imagined as a bi-dimensional table made of elements, all of them of a same uniform data type.

int arr[3][5]; represents a bi-dimensional array of 3 per 5 elements of type int.

Similarly a three dimensional array like int arr[3][4][2]; represent an outer array of three elements, each of which is a two dimensional array of four rows, each of which is a one dimensional array of five elements.

For example, the multidimensional array is stored in memory just like an one-dimensional array shown below:

int arr[3][4][2] = { { {1,2},{3,4},{5,6},{7,8} },
                            { {9,1},{1,2},{3,7},{4,7} },
                            { {6,1},{18,19},{20,21},{22,23} },
                             };


88. How Is Multidimensional Arrays Defined In Terms Of An Array Of Pointer? What Does Each Pointer Represent?

Answer: An element in a multidimensional array like two-dimensional array can be represented by pointer expression as follows:

*(*(a+i)+j)

It represents the element a[i][j]. The base address of the array a is &a[0][0] and starting at this address, the compiler allocates contiguous space for all the element row-wise. The first element of second row is immediately after last element of first row and so on.


89. What Do You Understand By Row-Major Order & Column-Major Order Of Arrays?

Answer: A two-dimensional array is declared like the way we declare a one-dimensional array except that we specify the number of elements in both dimensions. For example,
int grades[3][4];

The first bracket ([3]) tells the compiler that we are declaring 3 pointers, each pointing to an array. We are not talking about a pointer variable or pointer array. Instead, we are saying that each element of the first dimension of a two-dimensional array reference a corresponding second dimension. In this example, all the arrays pointed to by the first index are of the same size.

The second index can be of variable size. For example, the previous statement declares two-dimensional array where there are 3 elements in the first dimension and 4 elements in the second dimension.

Two-dimensional array is represented in memory in following two ways:
  • Row major representation: To achieve this linear representation, the first row of the array is stored in the first memory locations reserved for the array, then the second row and so on.
  • Column major representation: Here all the elements of the column are stored next to one another.

In row major representation, the address is calculated in a two dimensional array as per the following formula

The address of a[i] [j] =base (a) + (i*m+ j) * size

where base(a) is the address of a[0][0], m is second dimension of array a and size represent size of the data type.

Similarly, in a column major representation, the address of two-dimensional array is calculated as per the following formula

The address of a[i] [j] = base (a) + (j*n +i) * size

Where base (a) is the address of a [0] [0], n is the first dimension of array a and size represents the size of the data type.


90. What Is Meant By The Terms Row-Major Order & Column-Major Order?

Answer: Storing the array column by column is known as column-major order and storing the array row by row is known as row-major-order. The order used depends upon the programming language, not the user. For example, consider array A (3,4) and how this array will be stored in memory in both the cases is shown below



91. Can The Size Of An Array Be Declared At Runtime?

Answer: No, the size of an array can't be declared at run time, we always need to mention the dimensions of an array at the time of writing program i.e. before run time.


92. The Array DATA [10, 15] Is Stored In Memory In Row - Major Order. If Base Address Is 200 & Element Size Is 1. Calculate The Address Of Element DATA [7, 12].

Answer: 
Base address = 200
Element Size = l
Address of element DATA [7,12] = 200+[(7-l)*15+(12-l)]*l
= 200+[6*15+11]
= 200+[90+11]=301
Address of DATA [7,12] = 301


93. What Is A Pointer In C?

Answer: A pointer in C is a variable. It contains the memory address, i.e, locations of another variable which is declared as the pointer type.


94. What Are The Advantages Of Using Pointers?

Answer: Pointers help to save memory spaces.
  • Use of pointer assigns the memory space and also releases it. This helps in making best use of the available memory. In other words, it caters to dynamic memory allocation.
  • With pointers, data manipulation is done with address, so execution becomes faster.
  • Array representation is easy with pointers.

95. Write At Least Three Disadvantages Of A Pointer In C Programming?

Answer: Three important disadvantages of pointers are:
  • Uninitialized pointers might cause segmentation fault and if If pointers are updated with incorrect values, it might lead to memory corruption.
  • Dynamically allocated block needs to be freed explicitly.  Otherwise, it would lead to memory leak.
  • Pointers are slower than normal variables.

96. Discuss The Similarity Between Array & Pointer In C. 

Answer: Arrays are closely related to pointers in C programming but the important difference between them is that, a pointer variable takes different addresses as value whereas, in case of array it is fixed.


97. What Is The Purpose Of The Sizeof() Operator?

Answer: The sizeof() operator is a unary operator. This operator gives the size of its argument in terms of bytes. The argument can be a variable, array or any data type. This operator also gives the size of any structure.


98. What Is A Wild Pointer In C?

Answer: A wild pointer in C refers to a pointer which has not been initialized with any particular value. Wild pointer does not point to any specific memory location.


99. What Is The Size Of The Void Pointer In C?

Answer: The size of void pointer in C is two bytes.

100. What Are The Uses Of The Void Data Type?

Answer: The void data type is used basically to declare generic pointers. They are also used as a function parameter and as a function return type.


101. What Is A Generic Pointer/Void Pointer? In C, Why Is The Void Pointer Useful? When Would You Use It?

Answer: Void pointer is called generic pointer in C, because it can hold address of any type of object.

int a = 10;
int * p = &a; // Pointer to integer variable
double b = 10.2;
double * q = &b; // Pointer to double variable
void * r = &a; // Valid 
r = &b; // Valid 
        // because r is a generic pointer 
        // which can hold address of any type of memory block.  

The void pointer is useful because it is a generic pointer that any pointer can be cast into and back again without loss of information.


102. What Are The Uses Of Pointers In C Programming?

Answer: Pointers in C programming can be used in the following cases:
  • To access array elements.
  • For dynamic memory allocation.
  • For Call by reference.
  • In data structures like trees, graph, linked list etc.

103. What Is A Huge Pointer?

Answer: Huge pointers are 32 bit long containing segment address and offset address. Huge pointers are normalized pointers so for any given memory address there is only one possible huge address segment: offset pair. Huge pointer arithmetic is done with calls to special subroutines so its arithmetic slower than any other pointers.



104. What Is A Near Pointer?

Answer: A near pointer is 16 bits long. It uses the current content of the CS (code segment) register (if the pointer is pointing to code) or current contents of DS (data segment) register (if the pointer is pointing to data) for the segment part, the offset part is stored in a 16 bit near pointer. Using near pointer limits the data/code to 64KB segment.


105. How Many Bytes Are Occupied By Near, Far & Huge Pointers?

Answer: The near pointer is 2 bytes long and far and huge pointers are 4 bytes long.


106. What Are Dangling Pointers?

Answer: Dangling pointer is a concept which results when you have a pointer pointing to a location in memory that is meaningless. For example, consider the function

void DanglingPointer(int *x)
{
int y=0;
x = &y;
return;
}

When the function is called, space is allocated for the variable y on the stack, and the pointer x contains the address of that space. But when the function returns control to the calling function, the space that was allocated for y is cleared and x points to a meaningless location in memory


107. What Is A NULL Pointer? Whether It Is Same As An Uninitialized Pointer? What Does The Error ‘Null Pointer Assignment’ Means & What Causes This Error?

Answer: Null pointer is a pointer which points to nothing but uninitialized pointer may point to anywhere.

As null pointer points to nothing so accessing an uninitialized pointer or invalid location may cause an error.


108. Are Pointers Integer?

Answer: No, pointers are not integers. A pointer is an address. It is a positive number.


109. What Is Generic Pointer In C?

Answer: In C void* acts as a generic pointer. When other pointer types are assigned to generic pointer, conversions are applied automatically (implicit conversion).


110. How Pointer Variables Are Initialized?

Answer: Pointer variables are initialized by one of the following ways.
  • Static memory allocation.
  • Dynamic memory allocation.

111. What Is Pointer To A Pointer?

Answer: If a pointer variable points another pointer value. Such a situation is known as a pointer to a pointer. Example:

int *p1,**p2,v=10;
p1=&v;
p2=&p1;
Here p2 is a pointer to a pointer.


112. What Is An Array Of Pointers?

Answer: If the elements of an array are addresses, such an array is called an array of pointers.


113. Difference Between Array & Pointer?

Answer: Differences between array and pointers are:
  • Array allocates space automatically whereas pointer is explicitly assigned to point to an allocated space.
  • Arrays cannot be re-sized whereas pointers can be  sized using realloc().
  • Arrays cannot be reassigned whereas Pointer can be reassigned.
  • sizeof (array name) gives the number of bytes occupied by the array whereas Sizeof (p) returns the number of bytes used to store the pointer variable p.

114. What Are References. State The Differences Between Reference & Pointer.

Answer: Like a pointer, a reference is an alias for an object (or variable), is usually implemented to hold a machine address of an object (or variable), and does not impose performance overhead compared to pointers.

The notation X& means "reference to X".

Differences between reference and pointer are:
  • A reference can be accessed with exactly the same syntax as the name of an object.
  • A reference always refers to the object to which it was initialized.
  • There is no “null reference”, and we may assume that a reference refers to an object.

Two things to note on references:
  • One cannot have a pointer to a reference.
  • One cannot define an array of references.


115. Differentiate Between Pointers & Arrays With Example? 

Answer: Pointers and arrays are very closely linked in C. Consider the following statements:

int a[10], x;
int *ptr; /* ptr is a pointer variable*/
ptr = &a[0]; /* ptr points to address of a[0] */
x = *ptr;
/* x = contents of ptr (a[0] in this case) */
A pointer is a variable so we can do ptr = a and ptr++ ; while an array is not a variable so statements a = pa and a++ are illegal.


116. What Is The Size Of int Pointer, Float Pointer & Char Pointer In C In 32-bit Compiler & 64 bit Compiler?

Answer: In a 32 Bit compiler, size of Int Pointer, Char pointer & Float Pointer is 4 bytes and for 64 Bit compiler, size of Int Pointer, Char pointer & Float Pointer is 8 bytes


117. Difference Between An Array Name & A Pointer Variable?

Answer: A pointer variable is a variable where as an array name is a fixed address and is not a variable. A pointer variable must be initialized but an array name cannot be initialized. An array name being a constant value , ++ and -- operators cannot be applied to it.


118. Difference Between An Array Of Pointers & A Pointer To An Array?

Answer: Differences between the two are: Array of pointers:
  • Declaration of Array Of Pointers: data_type *array_name[size]; whereas Declaration of  Pointer To An Array data_type ( *array_name)[size];
  • Size represents the row size in case of Array Of Pointers whereas Size represents the column size in case of  Pointer To An Array.

119. What Are The Pointer Declarations Used In C?

Answer:

Array of pointers, e.g , int *a[10]; Array of pointers to integer
Pointers to an array,e.g , int (*a)[10]; Pointer to an array of int
Function returning a pointer,e.g, float *f( ) ; Function returning a pointer to float
Pointer to a pointer ,e.g, int **x; Pointer to a pointer to int
Pointer to a data type ,e.g, char *p; Pointer to char


120. Differentiate Between A Constant Pointer & Pointer To A Constant?

Answer: 

const char *p; // pointer to a const character.
char const *p; // pointer to a const character.
char * const p; // const pointer to a char variable.
const char * const p; // const pointer to a const character.


121. What Is The Invalid Pointer Arithmetic?

Answer: Invalid Pointer arithmetic are:
  • Adding, multiplying and dividing two pointers are not allowed.
  • Shifting or masking pointer.
  • Addition of float or double to pointer.
  • Assignment of a pointer of one type to a pointer of another type.

122. What Are The Advantages Of Using Array Of Pointers To String Instead Of An Array Of Strings?

Answer: Some of the advantages of using array of pointers to string over an array of strings are:
  • Efficient use of memory.
  • Easier to exchange the strings by moving their pointers while sorting.

123. Are The Expressions *ptr ++ & ++ *ptr Same?

Answer: No,*ptr ++ increments pointer and not the value pointed by it. Whereas ++ *ptr increments the value being pointed to by ptr.


124. Explain The Declaration int (*p (char *a))[10].

Answer: int (*p (char *a))[10];
interpretation of the above statement is:
int (*p (char *a))[10];
char *a :- pointer to character (Character Array)
(*p (Character Array))
int (*p (Character Array))
Integer pointer to character array
int (*p (Character Array))[10]
Array of integer pointer to character array
The given statement represent array of int pointer to char array.


125. What Is Increment Factor Term Used In Pointers?

Answer: While incrementing a pointer, its value gets increased by the length of the data type to which it points. This length is called increment factor.


126. When Are char[] & char * Treated As Same By The Compiler?

Answer: When using them as formal parameters while defining a function.


127. To free() We Only Pass The Pointer To The Block Of Memory Which We Want To Deallocate. Then How Does free() Know How Many Bytes It Should Deallocate?

Answer: In most implementations of malloc() the number of bytes allocated is stored adjacent to the allocated block. Hence it is simple for free() to know how many bytes to deallocate.


128. What Is A Far Pointer In C?

Answer: A far pointer in C refers to a pointer which is capable of pointing or accessing the whole of RAM’s residence memory. The far pointer can access all 16 segments of the residence memory.


128. What Are The Difference Between A Null Pointer, A Null Macro, The ASCII NUL Character & A Null String?

Answer: Differences between a null pointer, null macro and ascii null character, and a null string are:
  • A null pointer is a pointer which does not point anywhere.
  • A null macro is used to represent the null pointer in source code. It has a value 0 associated with it.
  • The ASCII Null character has all its bits as 0 but does not have any relation with null pointer.
  • The null string is just another name for an empty string "".


129. What Is A Structure?

Answer: A structure is a collection of data in which all the declared members are public by default. Data security is limited in structure. The general format of declaration of a structure is:

struct
{
Member1;
Member2;
……………….
……………….
Member m;
} var;


130. What Are The Differences Between A Structure & A Union?

Answer: A structure is a collection of data in which all the declared members are public by default. Data security is limited in structure.

Union is almost the same as the structure as structure contains members of different data types. In structure, each member has its own memory location whereas members of unions have same memory locations. We can assign values to only one member at a time in union.


131. How Can Typedef Be Used to Define A Type Of Structure?

Answer: typedef is used for defining new data types of structures. The general syntax is:

typedef type data_name;

Here, type is the data type and data_name is the name for that type.

For defining structures, typedef is used in the following manner:

typedef struct{
member1;
member2;
………………
} dataname;
Here, data name is another name for defining the structure.



132. What Is A Node? What Is A Linked List In C?

Answer: A node is the component of a linked list. Each node has two parts, first part contains the information field and second part contains the address of the next node. The address part of the last node of linked list will have NULL value.

A linked list is a self referential structure in which a member of a structure points to the structure itself. In other words, a linked list is a collection of elements called nodes.


133. What Is A Self Referential Structure? 

Answer: It is a structure that has a member that is of the same type as the structure in which it is defined. A common self-referential structure is a node in a linked-list, which is a member of a set of structures that are linked to one another with pointers. Each node of the linked-list is defined by the structure.


134. Differentiate Between Structure & Array.

Answer: Differences between structure and array are:
  • An array is a collection of related data elements of same type. Structure an have elements of different types.
  • An array is derived data type whereas a structure is a programmer-defined one.
  • Any array behaves like a built-in data type. Declare an array variable field use it. In the case of structure, first, data structure is to be designed and declared before the variables of that type are declared and used.

135. What Is A Union?

Answer: Union is a concept similar to a structure with the major difference in terms of storage. In the case of structures each member has its own storage location, but a union may contain many members of different types but can handle only one at a time. Union is also defined as a structure is done but using the syntax union.

Union var
{
 Int m;
 Char c;
 Float a;
}

Union var x;
Now x is a union containing three members m,c,a. But only one value can be stored either in x.m, x.c or x.a


136. Define A Structure. How It Is Different From Union?

Answer:  A structure contains an ordered group of data objects. Unlike the elements of an array, the data objects within a structure can have varied data types. Each data object in a structure is a member or field. A union is an object like a structure except that
  • In union, one block is used by all the member of the union but in case of structure, each member has their own memory space. All of union members start at the same location in memory. A union variable can represent the value of only one of its members at a time.
  • The size of the union is equal to the size of the largest member of the union whereas size of the structure is the sum of the size of all members of the structure.
For example
struct book
{
char name;
int pages;
float price;
};

Now if we define struct book book1, then it will assign 1+2+4=7 bytes of memory for book1.

If we define it as union like
union book
{
char name;
int pages;
float price;
};

The compiler allocates a piece of storage that is large enough to store the largest variable types in union. All three variables will share the same address and 4 bytes of memory is allocated to it.


137. Define A Structure To Store The Following Information About An Employee Name, Sex(male, female), Marital_Status(single, married, divorced or widowed), age.(using bit fields).

Answer:  Definition of a structure to store information of an employee:
struct employee
{
char name[20];
unsigned sex: 1;
unsigned martial_status: 1;
unsigned age: 7;
}emp;


138. Explain Pointers & Structures By Giving An Example Of Pointer To Structure Variable?

Answer:  We can have a pointer pointing to a structure just the same way a pointer pointing to an int, such pointers are known as structure pointers. For example, consider the following example:

struct student
{
char name[20];
int roll_no;
};

void main()
{
struct student stu[3],*ptr;
clrscr();
printf("\n Enter data\n");
for(ptr=stu;ptr{ printf("Name");
scanf("%s",ptr->name);
printf("roll_no");
scanf("%d",&ptr->roll_no);
}
printf("\nStudent Data\n\n");
ptr=stu;
while(ptr{
printf("%s %5d\n",ptr->name,ptr->roll_no); ptr++;
}
getch();
}

Here ptr is a structure pointer not a structure variable and dot operator requires a structure variable on its left. C provides arrow operator "->" to refer to structure elements. "ptr=stu" would assign the address of the zeroth element of stu to ptr. Its members can be accessed by statement like "ptr->name". When the pointer ptr is incremented by one, it is made to point to the next record, that is stu[1] and so on.



139. What Is Meant By Union?

Answer: Union is almost the same as the structure as structure contains members of different data types. In structure, each member has its own memory location whereas members of unions have same memory locations. We can assign values to only one member at a time in union.


140. What Are The Advantages Of Unions?


Answer: The greatest advantage of union is that it saves memory. When a union is declared, compiler automatically allocates a memory location to hold the largest data type of members in the union, thereby saving memory. Further, the concept of union is useful when it is not necessary to assign the values to all the members of the union at a time.


141. What Are Data Files? State The Two Types Of Data Files? State The Basic Difference Between The Two Data Files?


Answer: Data Files are to store data on the memory device permanently and to access whenever is required. There are two types of data files

  • Stream Oriented data files
  • System Oriented data files
Stream oriented data files are either text files or unformatted files. System oriented data files are more closely related to computer’s operating system and more complicated to work with.


142. What Are The Different Modes In Which A File Can Be Opened In C Programming?

Answer: Different modes for opening a file are tabulated below:
  • "r" Open text file for reading
  • "w" Open text file for writing, previous content, if any, discarded
  • "a" Open or create file for writing at the end of the file
  • "r+" Open text file for update
  • "w+" Create or open text file for update, previous content lost, if any
  • "a+" Open or create text file for update, writing at the end.

143. In Which Mode If The File Is Opened, The Content Of The File Will Be Lost?

Answer: When the mode is writing, the contents are deleted and the file is opened as a new file.


144. What Is A File? Write The Syntax For File Declaration. What Are Modes In File?

 Answer: A file is a collection of data that is available in permanent storage.

 syntax: FILE *filepointer;
 Ex: FILE *fp;

Mode tells about the types operations like read,write or append that can be performed on a file that is being opened.


145. Write The Syntax To Open A File. What Is The Significance Of fclose() Function?

Answer: 
 syntax: filepointer=fopen(FILENAME,MODE);
 Ex: fp=fopen(“in.dat”,r);

 This function closes a file that has been opened for an operation. Syntax:
fclose(filepointer);
 Ex: fclose(fp);



tags: c programming interview questions, interview questions on c language with answers, frequently asked questions in c with answers for interview, c questions and answers for interview, c test questions and answers, a c questions and answers, top 100 c interview questions and answers, technical interview questions and answers for freshers in c, sample c programming questions and answers, simple c interview questions and answers, tcs c interview questions and answers, questions and answers in c programming, c questions asked in technical interview,

Comments

Also Read

What Are Your Short Term Career Goals & Objectives? - Interview Answers

Tell Me Something About Yourself - Interview Answers.

What Are Your Expectations From The Job? - Job Interview Answers.