C Programming Interview

Ace your homework & exams now with Quizwiz!

What is a token?

A C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol.

What is a static function?

A function's definition prefixed with static keyword is called as a static function. You would make a function static if it should be called only within the same source code.

How a negative integer is stored.

Get the two's compliment of the same positive integer. Eg: 1011 (-5) Step-1 − One's compliment of 5 : 1010 Step-2 − Add 1 to above, giving 1011, which is -5

What is difference between including the header file with-in angular braces < > and double quotes " "

If a header file is included with in < > then the compiler searches for the particular header file only with in the built in include path. If a header file is included with in " ", then the compiler searches for the particular header file first in the current working directory, if not found then in the built in include path.

When should we use the register storage specifier?

If a variable is used most frequently then it should be declared using __________ storage specifier, then possibly the compiler gives CPU register for its storage to speed up the look up of the variable.

When to user -> (arrow) operator.

If the structure/union variable is a pointer variable, to access structure/union elements the arrow operator is used.

Where the address of operator (&) cannot be used?

It cannot be used on constants. It cannot be used on variable which are declared using register storage class.

What is the purpose of built-in stricmp() function.

It compares two strings by ignoring the case.

What is the purpose of the keyword typedef?

It is used to alias the existing type. Also used to simplify the complex declaration of the type.

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;)

Global Life

Life of a variable exists until the program is executing.

Local Life

Life of a variable is created when the function block is entered and destroyed on its exit.

Is FILE a built-in data type?

No, it is a structure defined in stdio.h.

Does a built-in header file contains built-in function definition?

No, the header file only declares function. The definition is in library which is linked by the linker.

Describe the file opening mode "w+"

Opens a file both for reading and writing. If a file is not existing it creates one, else if the file is existing it will be over written.

Which compiler switch to be used for compiling the programs using math library with gcc compiler?

Option -lm to be used as > gcc -lm <file.c>

What is a preprocessor?

Preprocessor is a directive to the compiler to perform certain things before the actual compilation process begins.

Explain the purpose of the function sprintf().

Prints the formatted output onto the character array.

S++ or S = S+1, which can be recommended to increment the value by 1 and why?

S++, as it is single machine instruction (INC) internally.

What are command line arguments?

The arguments/parameters which are sent to the main() function while executing from the command line/console are called so. All the arguments sent are the strings only.

Global Storage

The compiler decides the storage location of a variable.

What is lvalue and rvalue?

The expression appearing on right side of the assignment operator is called as rvalue. Rvalue is assigned to lvalue, which appears on left side of the assignment operator. The lvalue should designate to a variable not a constant.

What is the difference between actual and formal parameters?

The parameters sent to the function at calling end are called as actual parameters while at the receiving of the function definition called as formal parameters.

Global Scope

The scope of a variable is available throughout the program.

Local Scope

The scope of a variable is available within a function in which they are declared.

What is the meaning of base address of the array?

The starting address of the array is called as the base address of the array.

How many operators are there under the category of ternary operators?

There is only one operator and is conditional operator (? : ).

What is the purpose of extern storage specifier?

Used to resolve the scope of global symbol. Eg: main() { ______ int i; Printf("%d",i); } int i = 20;

Local Storage

Variables are stored in a stack unless specified.

Local Access

Variables can be accessed only by those statements inside a function in which they are declared.

What are bit fields?

We can create integer structure members of differing size apart from non-standard size using bit fields. Such structure size is automatically adjusted with the multiple of integer size of the machine.

Call by reference

We send address of the actual parameters instead of values. We choose this if we do want the actual parameters to be modified with formal parameters.

Call by value

We send only values to the function as parameters. We choose this if we do not want the actual parameters to be modified with formal parameters but just used.

What is the advantage of declaring void pointers?

When we do not know what type of the memory address the pointer variable is going to hold, then we declare a void pointer for such.

Does a break is required by default case in switch statement?

Yes, if it is not appearing as the last case and if we do not want the control to flow to the following case after default if any.

Can a program be compiled without main() function?

Yes, it can be but cannot be executed, as the execution requires main() function definition.

Signed-magnitude representation

a number's sign is represented with a sign bit: setting that bit (often the most significant bit) to 0 for a positive number or positive zero, and setting it to 1 for a negative number or negative zero. The remaining bits in the number indicate the magnitude (or absolute value).

C is Extensible

extensible language as it can adopt new features in the future

C is Simple

follows the structured approach, i.e., a program is broken into parts

Explain the syntax for 'for' loop.

for(expression-1;expression-2;expression-3) { //set of statements } When control reaches for expression-1 is executed first. Then following expression-2, and if expression-2 evaluates to non-zero 'set of statements' and expression-3 is executed, follows expression-2.

% c

format specifier used to display a character value

%f

format specifier used to display a floating point value

%s

format specifier used to print a string

%d

format specifier used to print an integer value

Which key word is used to perform unconditional branching?

goto

printf()

print the integer, character, float and string values on to the screen

C is Structured

program is broken into parts

What is a static variable?

retains its value between the function call and the default value is 0. The following function will print 1 2 3 if called thrice. void f() { ____ int i; ++i; printf("%d ",i); } If a global variable, then its visibility is limited to the same source code.

scanf()

take input from the user

format specifier

%

When C language developed

1972 at bell laboratories of AT&T

C Language

A mid-level and procedural programming language. The Procedural programming language is also known as the structured programming language is a technique in which large programs are broken down into smaller modules, and each module uses structured code. This technique minimizes error and misinterpretation.

What is a NULL statement?

A null statement is no executable statements such as ; (semicolon). Eg: int count = 0; while( ++count<=10 ) ; Above does nothing 10 times.

What is a pointer to a function? Give the general syntax for the same.

A pointer holding the reference of the function is called pointer to a function. In general it is declared as follows. T (*fun_ptr) (T1,T2...); Where T is any date type. Once fun_ptr refers a function the same can be invoked using the pointer as follows. fun_ptr(); [Or] (*fun_ptr)();

What is a dangling pointer?

A pointer initially holding a valid address, but later the held address is released.

What is a NULL pointer?

A pointer pointing to nothing is called so. Eg: char *p=____;

What is a nested structure?

A structure containing an element of another structure as its member is referred so

What is a self-referential structure?

A structure containing the same structure pointer variable as its element is called as self-referential structure.

Local Declaration

A variable which is declared inside function or block is known as a local variable.

Global Declaration

A variable which is declared outside function or block is known as a global variable.

Global Access

Any statement in the entire program can access variables.

Which operator is used to continue the definition of macro in the next line?

Backward slash (\) is used. #define MESSAGE "Hi, \ Welcome to C"

Distinguish between malloc() & calloc() memory allocation.

Both allocates memory from heap area/dynamic memory. By default calloc fills the allocated memory with 0's.

What is keyword auto for?

By default every local variable of the function is automatic (auto). In the below function both the variables 'i' and 'j' are automatic variables. void f() { int i; auto int j; } NOTE − A global variable can't be an automatic variable.

What are the different ways of passing parameters to the functions? Which to use when?

Call by value, Call by reference

Explain the use of %i format specifier w.r.t scanf().

Can be used to input integer in all the supported format.

Explain the use of comma operator (,).

Comma operator can be used to separate two or more expressions. Eg: printf("hi") , printf("Hello");

What is the difference between variable declaration and variable definition?

Declaration associates type to the variable whereas definition gives the value to the variable.

founder of C language

Dennis Ritchie

Explain modular programming.

Dividing the program in to sub programs (modules/function) to achieve the given task is modular approach. More generic functions definition gives the ability to re-use the functions, such as built-in library functions.

Which operator is used to receive the variable number of arguments for a function?

Ellipses (...) is used for the same. A general function definition looks as follows void f(int k,...) { }

What is reminder for 5.0 % 2?

Error, It is invalid that either of the operands for the modulus operator (%) is a real number.

How can you print a \ (backslash) using any of the printf() family of functions.

Escape it using \ (backslash).

Where an automatic variable is stored?

Every local variable by default being an auto variable is stored in stack memory

What are the valid places for the keyword break to appear.

appear only with in the looping control and switch statement. The purpose is to bring the control out from the said blocks.

C called a mid-level programming language

because it binds the low level and high -level programming language. We can use C language as a System programming to develop the operating system as well as an Application programming to generate menu driven customer driven billing system

0x00

bx0000 0000

0x01

bx0000 0001

0x02

bx0000 0010

0x03

bx0000 0011

0x04

bx0000 0100

0x05

bx0000 0101

0x06

bx0000 0110

0x07

bx0000 0111

0x08

bx0000 1000

0x09

bx0000 1001

0x0A

bx0000 1010

0x0B

bx0000 1011

0x0C

bx0000 1100

0x0D

bx0000 1101

0x0E

bx0000 1110

0x0F

bx0000 1111

0x10

bx0001 0000

What is the problem with the following coding snippet?

char *s1 = "hello",*s2 = "welcome"; strcat(s1,s2); s1 points to a string constant and cannot be altered.

C is Mid Level

combines the low- level language with the features of the high-level language

C has Memory Management

inbuilt memory function that saves the memory and improves the efficiency of our program

Declare pointer pointer

int **pptr;

C is Fast Speed

it uses a powerful set of data types and operators

C known as a mother language

most of the compilers in this language. Most of the languages which are developed after C language has borrowed heavily from it like C++, Python, Rust, javascript, etc. It introduces new core concepts like arrays, functions, file handling which are used in these languages

C is Portable

once the program is written can be run on any machine with little or no modifications.


Related study sets

Entrepreneurship and Small Business Management (18-19)

View Set

Combo with "Training instruction/ NCSF" and 10 others

View Set

Chapter 43: Nursing Care of the Child With a Genitourinary Disorder

View Set

Chapter 1 Intro Into Microeconomics

View Set

Excel Ch.2 Study Guide for ITE 115

View Set