C



1. What is C Language?  

C is a computer programming language. That means that you can use C to create lists of instructions for a computer to follow. C is one of thousands of programming languages currently in use. C has been around for several decades and has won widespread acceptance because it gives programmers maximum control and efficiency. C is an easy language to learn. It is a bit more cryptic in its style than some other languages, but you get beyond that fairly quickly.

C is what is called a compiled language? This means that once you write your C program, you must run it through a C compiler to turn your program into an executable that the computer can run (execute). The C program is the human-readable form, while the executable that comes out of the compiler is the machine-readable and executable form.
  • C language is a structure/procedure oriented, middle level programming language developed at Bell Laboratories in 1972 by Dennis Ritchie.
  • C language was invented for implementing UNIX operating system.
  • In 1978, Dennis Ritchie and Brian Kernighan published the first edition "The C Programming Language".
  • Also, C language is an ANSI/ISO standard and powerful programming language for developing real time applications


2. How do you construct an increment statement or decrement statement in C?  

There are actually two ways you can do this. One is to use the increment operator ++ and decrement operator -. For example, the statement "x++" means to increment the value of x by 1. Likewise, the statement "x -" means to decrement the value of x by 1. Another way of writing increment statements is to use the conventional + plus sign or - minus sign. In the case of "x++", another way to write it is "x = x +1".



3. What is the difference between declaration and definition of a variable/function?  

Declaration of a variable/function simply declares that the variable/function exists somewhere in the program but the memory is not allocated for them. But the declaration of a variable/function serves an important role. And that is the type of the variable/function. Therefore, when a variable is declared, the program knows the data type of that variable. In case of function declaration, the program knows what are the arguments to that functions, their data types, the order of arguments and the return type of the function. So that's all about declaration. Coming to the definition, when we define a variable/function, apart from the role of declaration, it also allocates memory for that variable/function. Therefore, we can think of definition as a super set of declaration. (or declaration as a subset of definition). From this explanation, it should be obvious that a variable/function can be declared any number of times but it can be defined only once. (Remember the basic principle that you can't have two locations of the same variable/function).
          // This is only declaration. y is not allocated memory by this statement 
          extern int y; 

         // This is both declaration and definition, memory to x is allocated by this statement.
         int x;
         


4. Where is C Programming Language used or uses of C Language?  

C language is used to develop system applications that forms major portion of operating systems such as Windows, UNIX and Linux. Operating systems, C compiler and all UNIX application programs are written in C language. Below are some examples of uses of C language.
  • Database systems
  • Graphics packages
  • Word processors
  • Spread sheets
  • Operating system development
  • Compilers and Assemblers
  • Network drivers
  • Interpreters



5. What is the difference between C and C++?  

Even though C and C++ programming languages are belonging to middle level languages, both are differed in below.
    • C is structure/procedure oriented programming language whereas C++ is object oriented programming language.
    • C language program design is top down approach whereas C++ is using bottom up approach.
    • Polymorphism, virtual function, inheritance, Operator overloading, namespace concepts are not available in C programming language. Whereas C++ language supports all these concepts and features.
    • C language gives importance to functions rather than data. Whereas C++ gives importance to data rather than functions.
    • So, data and function mapping is difficult in C. But, data and function mapping is simple in C++ that can be done using objects.
    • C language does not support user define data types. Whereas C++ supports user define data types.
    • Exception handling is not present in C programming language. Whereas exception handling is present in C++ language.
    • C language allows data to freely flow around the functions. But, data and functions are bound together in C++ which does not allow data to freely flow around the functions.


6. What is the difference between top down approach and bottom up approach in programming languages?  

Top down approach and bottom up approach are involved in software development. These approaches are not involved in program execution.
    • Structure/procedure oriented programming languages like C programming language follows top down approach. Whereas object oriented programming languages like C++ and Java programming language follows bottom up approach.
    • Top down approach begins with high level design and ends with low level design or development. Whereas, bottom up approach begins with low level design or development and ends with high level design.
    • In top down approach, main() function is written first and all sub functions are called from main function. Then, sub functions are written based on the requirement. Whereas, in bottom up approach, code is developed for modules and then these modules are integrated with main() function.
    • Now-a-days, both approaches are combined together and followed in modern software design.


7. What is the difference between Call by Value and Call by Reference?  

When using Call by Value, you are sending the value of a variable as parameter to a function, whereas Call by Reference sends the address of the variable. Also, under Call by Value, the value in the parameter is not affected by whatever operation that takes place, while in the case of Call by Reference, values can be affected by the process within the function.



8. Some coders debug their programs by placing comment symbols on some codes instead of deleting it. How does this aid in debugging?  

Placing comment symbols /* */ around a code, also referred to as "commenting out", is a way of isolating some codes that you think maybe causing errors in the program, without deleting the code. The idea is that if the code is in fact correct, you simply remove the comment symbols and continue on. It also saves you time and effort on having to retype the codes if you have deleted it in the first place.



9. What is the equivalent code of the following statement in WHILE LOOP format?  

        for (a=1; a<=100; a++)
        printf ("%d\n", a * a);
        
Answer:
        a=1;
        while (a<=100) {
        printf ("%d\n", a * a);
        a++;
        }
        


10. What is spaghetti programming?  

Spaghetti programming refers to codes that tend to get tangled and overlapped throughout the program. This unstructured approach to coding is usually attributed to lack of experience on the part of the programmer. Spaghetti programing makes a program complex and analyzing the codes difficult, and so must be avoided as much as possible.



11. What is a stack?  

A stack is one form of a data structure. Data is stored in stacks using the FILO (First In Last Out) approach. At any particular instance, only the top of the stack is accessible, which means that in order to retrieve data that is stored inside the stack, those on the upper part should be extracted first. Storing data in a stack is also referred to as a PUSH, while data retrieval is referred to as a POP.



12. What is a sequential access file?  

When writing programs that will store and retrieve data in a file, it is possible to designate that file into different forms. A sequential access file is such that data are saved in sequential order: one data is placed into the file after another. To access a particular data within the sequential access file, data has to be read one data at a time, until the right one is reached.



13. What is variable initialization and why is it important?  

This refers to the process wherein a variable is assigned an initial value before it is used in the program. Without initialization, a variable would have an unknown value, which can lead to unpredictable outputs when used in computations or other operations.



14. Differentiate Source Codes from Object Codes?  

Source codes are codes that were written by the programmer. It is made up of the commands and other English-like keywords that are supposed to instruct the computer what to do. However, computers would not be able to understand source codes. Therefore, source codes are compiled using a compiler. The resulting outputs are object codes, which are in a format that can be understood by the computer processor. In C programming, source codes are saved with the file extension .C, while object codes are saved with the file extension .OBJ



15. In C programming, how do you insert quote characters (' and ") into the output screen?  

This is a common problem for beginners because quotes are normally part of a printf statement. To insert the quote character as part of the output, use the format specifiers \' (for single quote), and \" (for double quote).



16. What is a pointer on pointer?  

It's a pointer variable which can hold the address of another pointer variable. It de-refers twice to point to the data held by the designated pointer variable.
Eg: int x = 5, *p=&x, **q=&p;
Therefore 'x' can be accessed by **q.


17. When should we use pointers in a C program?  

1. To get address of a variable 2. For achieving pass by reference in C: Pointers allow different functions to share and modify their local variables. 3. To pass large structures so that complete copy of the structure can be avoided. C 4. To implement “linked” data structures like linked lists and binary trees.



18. What is NULL pointer?  

NULL is used to indicate that the pointer doesn't point to a valid location. Ideally, we should initialize pointers as NULL if we don't know their value at the time of declaration. Also, we should make a pointer NULL when memory pointed by it is deallocated in the middle of a program.It's symbol is '\0'.



19. What is scope of a variable? How are variables scoped in C?  

Scope of a variable is the part of the program where the variable may directly be accessible. In C, all identifiers are lexically (or statically) scoped.



20. How will you print "Hello World" without semicolon?  

        int main(void)
        {
            if (printf("Hello World")) ;
        }
           


Java Interview Question

.Net Interview Question

PHP Interview Question

AngularJS Interview Questions