Search Site
Loading
Advertisements
Free Download Project
Asp.Net Project
Vb.Net Project
Php Project
Java Project
C/C++ Project
Android Project
Others Project
Latest Seminar
Free Download Latest Seminar
Study Material
Free Download Lecture Note For Computer Science
Free Download Lecture PPT For Computer Science
Placement Paper
Company Placement Paper
Gate Paper
Miscellneous
Best Project Ideas
Interviews Questions For Freshers
Request
Feedback

 

Join With Facebook

Advertisements


Common Interview Questions and answer of Progamming C for Computer Science , Software Engineering,BCA,MCA & IT. all important interview questions with answers and simple facts to succeed in any interview. Here you can share and discuss answers so that visitors can benefit from the contributions. Also you can share your experience, questions or answers, you feel will help freshers or experienced candidates to succeed in interviews.
Interview questions and answer of Programming C

Q:- What is C language?

Ans:-The C programming language is a standardized programming language developed in the early 1970s by Ken Thompson and Dennis Ritchie for use on the UNIX operating system. It has since spread to many other operating systems, and is one of the most widely used programming languages. C is prized for its efficiency, and is the most popular programming language for writing system software, though it is also used for writing applications.

Q:-What is the difference between "printf(...)" and "sprintf(...)"?

Ans:-sprintf(...) writes data to the character array whereas printf(...) writes data to the standard output device.

Q:-What does static variable mean?

Ans:-there are 3 main uses for the static. 1. If you declare within a function:
It retains the value between function calls
2.If it is declared for a function name:
By default function is extern..so it will be visible from other files if the
function declaration is as static..it is invisible for the outer files
3. Static for global variables:
By default we can use the global variables from outside files If it is
static global..that variable is limited to with in the file

Q:-Advantages of a macro over a function?

Ans:-Macro gets to see the Compilation environment, so it can expand __ __TIME__ __FILE__ #defines. It is expanded by the preprocessor.
For example, you can’t do this without macros
#define PRINT(EXPR) printf( #EXPR “=%d\n”, EXPR)
PRINT( 5+6*7 ) // expands into printf(”5+6*7=%d”, 5+6*7 );
You can define your mini language with macros:
#define strequal(A,B) (!strcmp(A,B))
Macros are a necessary evils of life. The purists don’t like them, but without it no real work gets done.

Q:-What are the differences between malloc() and calloc()?

Ans:-There are 2 differences. First, is in the number of arguments. malloc() takes a single argument(memory required in bytes), while calloc() needs 2 arguments(number of variables to allocate memory, size in bytes of a single variable). Secondly, malloc() does not initialize the memory allocated, while calloc() initializes the allocated memory to ZERO.

Q:-Difference between const char* p and char const* p

Ans:-You can’t, really. free() can , but there’s no way for your program to know the trick free() uses. Even if you disassemble the library and discover the trick, there’s no guarantee the trick won’t change with the next release of the compiler.

Q:-Can a variable be both const and volatile?

Ans:-Yes. The const modifier means that this code cannot change the value of the variable, but that does not mean that the value cannot be changed by means outside this code. For instance, in the example in FAQ 8, the timer structure was accessed through a volatile const pointer. The function itself did not change the value of the timer, so it was declared const. However, the value was changed by hardware on the computer, so it was declared volatile. If a variable is both const and volatile, the two modifiers can appear in either order.

Q:-What is the difference between text and binary modes?

Ans:-Streams can be classified into two types: text streams and binary streams. Text streams are interpreted, with a maximum length of 255 characters. With text streams, carriage return/line feed combinations are translated to the newline n character and vice versa. Binary streams are uninterrupted and are treated one byte at a time with no translation of characters. Typically, a text stream would be used for reading and writing standard text files, printing output to the screen or printer, or receiving input from the keyboard. A binary text stream would typically be used for reading and writing binary files such as graphics or word processing documents, reading mouse input, or reading and writing to the modem.

Q:-What is static memory allocation and dynamic memory allocation?

Ans:-Static memory allocation: The compiler allocates the required memory space for a declared variable.By using the address of operator,the reserved address is obtained and this address may be assigned to a pointer variable.Since most of the declared variable have static memory,this way of assigning pointer value to a pointer variable is known as static memory allocation. memory is assigned during compilation time.
Dynamic memory allocation: It 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 functions are assingned to pointer variables, such assignments are known as dynamic memory allocation.memory is assined during run time.

Q:-How are pointer variables initialized?

Ans:-Pointer variable are initialized by one of the following two ways
- Static memory allocation
- Dynamic memory allocation

Q:-Difference between arrays and pointers?

Ans:-- Pointers are used to manipulate data using the address. Pointers use * operator to access the data pointed to by them
- Arrays use subscripted variables to access and manipulate data. Array variables can be equivalently written using pointer expression

Q:-What is a method?

Ans:-Method is a way of doing something, especially a systematic way; implies an orderly logical arrangement.

Q:-What is indirection?

Ans:-If you declare a variable, its name is a direct reference to its value. If you have a pointer to a variable, or any other object in memory, you have an indirect reference to its value.

Q:-What is modular programming?

Ans:-If a program is large, it is subdivided into a number of smaller programs that are called modules or subprograms. If a complex problem is solved using more modules, this approach is known as modular programming.

Q:-How many levels deep can include files be nested?

Ans:-Even though there is no limit to the number of levels of nested include files you can have, your compiler might run out of stack space while trying to include an inordinately high number of files. This number varies according to your hardware configuration and possibly your compiler.

Q:-What is the difference between declaring a variable and defining a variable?

Ans:-Declaring a variable means describing its type to the compiler but not allocating any space for it. Defining a variable means declaring it and also allocating space to hold the variable. You can also initialize a variable at the time it is defined.

Q:-What is an lvalue?

Ans:-An lvalue is an expression to which a value can be assigned. The lvalue expression is located on the left side of an assignment statement, whereas an rvalue is located on the right side of an assignment statement. Each assignment statement must have an lvalue and an rvalue. The lvalue expression must reference a storable variable in memory. It cannot be a constant.

Q:-Differentiate between an internal static and external static variable?

Ans:-An internal static variable is declared inside a block with static storage class whereas an external static variable is declared outside all the blocks in a file.An internal static variable has persistent storage,block scope and no linkage.An external static variable has permanent storage,file scope and internal linkage.

Q:-What is the difference between a string and an array?

Ans:-An array is an array of anything. A string is a specific kind of an array with a well-known convention to determine its length.
There are two kinds of programming languages: those in which a string is just an array of characters, and those in which it’s a special type. In C, a string is just an array of characters (type char), with one wrinkle: a C string always ends with a NUL character.
The “value” of an array is the same as the address of (or a pointer to) the first element; so, frequently, a C string and a pointer to char are used to mean the same thing.
An array can be any length. If it’s passed to a function, there’s no way the function can tell how long the array is supposed to be, unless some convention is used. The convention for strings is NUL termination; the last character is an ASCII NUL (‘’) character.

Q:-What is an argument? Differentiate between formal arguments and actual arguments?

Ans:-An argument is an entity used to pass the data from calling function to the called function. Formal arguments are the arguments available in the function definition. They are preceded by their own data types. Actual arguments are available in the function call.

Q:-What are advantages and disadvantages of external storage class?

Advantages of external storage class
1)Persistent storage of a variable retains the latest value
2)The value is globally available
Disadvantages of external storage class
1)The storage for an external variable exists even when the variable is not needed
2)The side effect may produce surprising output
3)Modification of the program is difficult
4)Generality of a program is affected

Q:-What is a void pointer?

Ans:-A void pointer is a C convention for a raw address. The compiler has no idea what type of object a void Pointer really points to. If you write int *ip; ip points to an int. If you write void *p; p doesn’t point to a void! In C and C++, any time you need a void pointer, you can use another pointer type. For example, if you have a char*, you can pass it to a function that expects a void*. You don’t even need to cast it. In C (but not in C++), you can use a void* any time you need any kind of pointer, without casting. (In C++, you need to cast it). A void pointer is used for working with raw memory or for passing a pointer to an unspecified type. Some C code operates on raw memory. When C was first invented, character pointers (char *) were used for that. Then people started getting confused about when a character pointer was a string, when it was a character array, and when it was raw memory.

Q:-When should a type cast not be used?

Ans:-A type cast should not be used to override a const or volatile declaration. Overriding these type modifiers can cause the program to fail to run correctly. A type cast should not be used to turn a pointer to one type of structure or data type into another. In the rare events in which this action is beneficial, using a union to hold the values makes the programmer’s intentions clearer.

Q:-When is a switch statement better than multiple if statements?

Ans:-A switch statement is generally best to use when you have more than two conditional expressions based on a single variable of numeric type

Q:-What is a static function?

Ans:-A static function is a function whose scope is limited to the current source file. Scope refers to the visibility of a function or variable. If the function or variable is visible outside of the current source file, it is said to have global, or external, scope. If the function or variable is not visible outside of the current source file, it is said to have local, or static, scope.

Q:-What is a pointer variable?

Ans:-A pointer variable is a variable that may contain the address of another variable or any valid address in the memory.

Q:-What is a pointer value and address?

Ans:-A pointer value is a data object that refers to a memory location. Each memory location is numbered in the memory. The number attached to a memory location is called the address of the location.

Q:-What is a modulus operator? What are the restrictions of a modulus operator?

Ans:-A Modulus operator gives the remainder value. The result of x%y is obtained by (x-(x/y)*y). This operator is applied only to integral operands and cannot be applied to float or double.