Quick answers and things to know on c language

Data Types and Constants & Variables

1.In little-endian systems addresses are always in ABCD and data is stored in DCBA order

2.In big-endian system addresses are always in ABCD and data is stored in ABCD order

3.Cycle is present in integer and character data type but not present in float or double types

4.Increments the value of a float or double variable beyond its maximum range that is +INF and beyond it minimum range is –INF

5.The minimum octal character constant is ‘00’ and maximum octal character constant is ‘377’

6.Very first escape sequence character is ‘a’ and last escape sequence character is ‘r’

7.Float data always stores in memory mantissa and exponent format

8.Enum data types creates a sequence sets of integral constants

9.There is no cycle present in enum data type

10.BCPL is a type less language

11.When a language is able to produce a new data type that is called extensibility

12.Data types tells to compiler how much memory will be allocated in load time and runtime of the program

13.Tyepdef creates a new name but does not create a new type

14.Addresses in memory always in ABCD format but data store in memory in ABCD or DCBA that depends on system

15.The process of byte ordering is known as endeaness

16.32 bits recurring binary of a float is always lesser than 64 bits recurring binary of a float

17.When a signed negative integer compared with an unsigned integer , its binary level of variable is compared not their value level

18.Signed and unsigned modifier is not allowed in float or double data types

19.All constants in C are R-value category of objects

20.Constant variables, array name, function name, enum constants are R-value category of objects

21.All escape sequence characters are octal character constants

22.The size of the null string constant is 1 byte

23.‘’ is null character constant whose ASCII value is 0

24.Length of the Variable name beyond 32 characters are no use in TC

25.Void type is used in three different places, such as
a. No argument to a function
b. No Return type
c. Generic Pointer
26.How many constants in C: as many variable in C

27.Size of integer type depends on compiler or word length of the processor

28.Float follows 23 bits mantissa,11 bits exponent and 1 bit sign.

29.C Language supports 256 characters. Out of them 127 ASCII( 26+26 alphabets,10 digits,32 special character,33 control character) and 129 Extended ASCII characters

Operators

1.Precedence and associativity of an operator only implemented if it is represented in INFIX notation

2.Precedence decides which operation will be performed first

3.Associativity decides the order of evaluation ( left to right or right to left) if more than one operator enjoy same precedence

4.The operator which requires three operands that is called ternary operator

5.? : is a conditional ternary operator

6.Associativity of a comma ( , ) operator is left to right

7.# is a string forming operator that convert a non-string data to string and used only in preprocessor directives
8.There is no operator in C to calculate the raise of a number

9.Bit wise operators only works in integral type but does not work in float type

10.Return value of relational and logical operators is 0 or 1

11.x++, Here Microprocessor does both read and write operation

Control Structure

1. Hanging if is not allowed in C

2. If statement is used for checking range and yes/no problem

3. else is the optional part of the if

4. Execution of switch case starts from the match case.

5. Use break to prevent the falling of control from one case to another case

6. If none of the cases are satisfied then default case will be satisfied

7. Case character only can be integral constant.

8. Switch case only checks integral does not check float

9. Continue can not be the part of the switch case.

10. Switch without case no use ( no output no error)

11. Duplicate case is not allowed in C

12. Switch case is the replacement of if…else statement

13. Switch case is used for selection control statement

14. Loop counter can be int, char and float

15. If loop counter is not initialized in a loop , that is called odd loop

16. Loop is an alternate of function recursion and function recursion is an alternate of loop

17. for loop is suitable for finite loop , while loop is suitable for unknown loop and do while loop is suitable for at least once

18. loop counter has its own block scoping

19. Drop all the parts of for loop is an infinite loop but drops all part of while and do while loop is an error

20. break in loop transfer control outside the loop

21. continue transfer the control to beginning of loop

22. If loop counter exceeds its range , it will be infinite loop

23. Every loop has start value, step value and stop value

24. If loop loses its step value , it will be an infinite loop

25. Repeating some parts of program and Software delay use loop

26. Loop is faster than function recursion

Pointer

1. When a pointer points to zero , that is called null pointer

2. Generic pointer can not be dereference

3. Arithmetic is not allowed in generic pointer

4. Return type of malloc and calloc function is generic pointer

5. Address + 1 = next address of its type

6. When a pointer points an invalid address, then it will be called Wild pointer

7. When the pointer lost reference, then it will be called memory leak

8. Size of a pointer in gcc is 4 bytes

9. In TC , When a pointer works within 64KB memory , then it is called near pointer. But when the pointer works beyond 64KB Memory , then it is called far pointer

10. Dereferencing to a wild pointer is called core dump

11. When the pointer address becomes invalid in a program , then it is called dangling pointer

12. Function name and array name are known as constant pointers

13. When more than one pointer refers to same location and one of them is modifying the resource , at the same moment other are waiting , then that pointer must be restrict pointer

14. Dynamic memory allocation is possible using pointer

15. Randomly Access any memory cell of a variable use pointer

16. A Function can be called or invoke using function pointer

Array

1. Array name is a constant pointer which gives the address of the 0th element of an array

2. Limitation of an array is

a) Unused memory of an array can’t be used
b) Array size can’t be changed in run time
3. One array can’t be assigned to another array, because both are constant pointer.

4. Turbo C does not allow zero length array size but GCC allow zero length and variable length array size.

5. The size of the zero length array size is 0

6. One array can not directly copy to another array by just equating two.

7. Array name can not be incremented and decremented, because it is a constant pointer.

8. Malloc memory allocation is single dimensional array equivalent and calloc memory allocation is double dimensional array equivalent

9. The major difference between strcpy and strncpy is strcpy copy the whole string includes null character but strncpy dose not copy null character.

10. Double dimensional array is a collection of single dimensional array, where each single dimensional array must be used for different purpose

11. Visiting double dimensional array in row major is always faster than column major.

12. Array name + 1 = Address of next element if it is single dimensional array

13. Array name + 1 = Address of next array if it is double dimensional array

14. To get address of any element of a double array use

15. Address = base address+(row number * row size + col number) + size of element

16. Array can be represented as subscript and pinter format

Dynamic Memory Allocation

1. Dynamic Memory Allocation in C is a part of Heap area.

2. Memory allocation in C is possible through variables and functions.

3. Basically dynamic memory allocation is done by a family of 3 functions in C, such as malloc( ), calloc( ) and realloc().

4. Malloc,calloc and realloc always allocate memory above the break pointer.

5. Break pointer is initial entry point in heap.

6. brk and sbrk function is used to set and retrieve the break pointer

7. Memory allocated in heap remains in existence for the duration of a program.

8. When memory is allocated from heap area using functions, there addresses are growing upwards and heap size is decreasing and

9. when memory is free heap size is increasing.

10. Free means break pointer is decreasing in last break pointer – malloc size – 8

11. Static allocation: When you declare a static and global variable in C program that reserves block of space, of a fixed size when program

12. is loaded and never free before program is unloaded.

13. Static allocation is a part of Data or BSS area

14. Automatic allocation: When you declare automatic variables, such as function actual argument and local variables in C program that reserves

15. memory when control entered in scope and automatically free when a control leaves the scope.

16. Automatic memory allocation is a part of stack area

17. Dynamic memory allocation is not supported by C variables; there is no storage class called “dynamic” to allocate memory dynamically

18. from the process memory in run time.

19. Realloc allocates memory always relative to the last block of malloc or calloc to resize the memory block.

20. Malloc memory allocation is single dimensional array equivalent and calloc memory allocation is double dimensional array equivalent.

21. After free Pointer should be initialized with 0 to overcome the core dump.

Function

1. Function return value, function parameter, local automatic variables of a function stores in stack area

2. If function return type is non integer prototype is required

3. Function at a time returns only one value

4. Copy of the variable is created when it is ‘pass by value’

5. When a function called to itself directly or indirectly, that is called function recursion.

6. Function recursion is an alternate of loop

7. Function recursion always follows LIFO data structure

8. The size of the function is (called Function Frame) is manually calculated in the following way

a. Size of the local auto variables
b. Size of function parameter,
c. Size of the return value
d. Size of base address of the next function

9. Library is a special file which hides detail about the functionalities of a function

10. When a program is linking with static library , all symbols present in static library will be copied to program

11. A function can be called in two different ways, such as

a) function name followed by ( )
b) pointer to function

12. Function convert generic style program to modular style

13. Functions are created in memory in a form of doubly linked list, which follow LIFO data structure

Storage Classes

1. Storage class decides the scope, life, storage and default initial value of a variables, and functions

2. Storage Class follows four kinds of scoping rules such as

3. block scoping
4. function scoping
5. file scoping
6. program scoping
7. Static storage class is used in three different places, such as
• File scoping
• Sharing the same memory location in different frames of function recursion
• To avoid reinitialization of a variables
8. Extern storage class is used for program scoping

9. If a variable is defined in one file and that can be accessed in other file in the same program , we can say variable has a program scoping

10. If a variable is defined in one file and that can’t be accessed in other file in the same program , we can say variable has a file scoping

11. Auto storage class allocates and de-allocates memory automatically from stack area

12. Register variable has no memory address , so pointer can’t work with register variables

13. Access time of register variable is 1 nanosecond but auto, static and extern variable is 200 nanosecond

Preprocessors

1. When macro takes parameter , that is called parameterized macro or macro call

2. Startup pragma is executed very first before control goes to main and exit pragma is executed at last once control leaves main

3. The C preprocessor CPP only process source file such as .C .cpp but does not process object and executable file

4. The file inclusion preprocessor directive include file using “ “ or < > where “ “ search the file from the current directory path and std. include path but < > searches the file only from the std.include path.

5. # is used as string forming ## is used as token pasting operator

Structure and Union

1. If a structure contains a slack byte , that is called imbalance structure

2. Word alignment is required to make imbalance structure to balance structure

3. Same structure can not be nested within same structure, because it is a restriction in C

4. Same structure can be nested within same structure if nested structure is a pointer , that is called self-referential structure

5. Structure is used for data encapsulation, memory link and bit-fields

6. Two structure variable can not be compared because it is the restriction in C

7. One structure variable can be assigned to another structure variable if both are belongs to same structure

8. Offset of command is used to measure the byte offset of a structure

9. Bit field is a unique feature in C which can be applied to a structure for memory optimization

10. Bit field range must be 1 to size of data member

11. Bit field is not allowed to float data members

12. The very first member of the union is active member

13. First member of the union only can be initialized at the time of definition and rest can’t be initialized

14. Union provides a technique to share a common memory in different ways

15. The longest data member size is the union size

16. Properties of union depends on the type of first data member

17. Active data member must be the longest data member, otherwise message can’t pass to the other data member

18. Union is used for memory optimization, Creating message format and share memory or locking mechanism

19. Each Data member of a union begins at same place, But each data member of a structure begins at different places

20. Byte offset of the union data member is always 0.

21. To create a memory link or linked list we need a structure and that structure must be a self-referential structure

22. Data member can be access using . notation or -> notation

Files and Command line

1. The flow of data from buffer to device or device to buffer is called stream. When data moves from device to buffer called input stream and buffer to device is called output stream.

2. When operating system allocates memory from a RAM for special use , that memory is called buffer, In Linux buffer size is 4K

3. The contents of file stores in Data Block of Disk.

4. The active file pointer write_ptr and read_ptr move automatically to next character when any read/write operation is perform

5. When a stream is not associated in memory its file descriptor value is -1

6. getc return -1 when it reads ctrl+ z character

7. EOF is a macro whose expansion of -1 which is End of File indicator

8. File handling is possible using std.library and system calls

9. Read/Write operation using std.library and system call are possible in buffer instead of file

10. When a program is loaded by default stdin,stdout,stderr is loaded.

11. fwrite and fread only works with low level file

12. There are three file opening modes , such as read, write and append

13. Program takes input from different input devices, such as keyboard, scanner, mouse. Where as command line is used as another input media to a program

14. In command line argument process uses argument counter, argument vector and environment vector .

15. Space is used as separator from one parameter to another parameter in command line argument.

16. Every parameter in command line argument is string types

17. Argument vector and Environment vector is an array of string types

18. argc,argv and env are used generally in command line argument

Miscellaneous

1. Execution of C program begin at main function but end at null statement

2. Width of the Data Bus is known as Word length of the processor

3. If programming language uses 16 bits word length that is called 16 bits programming , if uses 32 bits word length that is called 32 bits programming

4. The running program of a computer is called process

5. The process memory of a process is divided into different segment such as code, data ,bss ,heap and stack segment

6. How much memory is accessible by the program that depends on width of the address bus of microprocessor

7. Page table is used to translate virtual address to physical address in LINUX operating system

8. Segmentation unit is used to translate logical address to virtual address

9. To translate a 16 bits offset address and 32 bits far address into 20 bits real address ,MSDOS uses segment address *16 + offset address

10. All automatic variables are created in stack area, so their address is always growing down order.

11. All Intel processors are little Endean processor But Motorola , power pc and Macintosh are big Endean processor

12. When operating system required 4GB physical memory , at the same moment RAM does not supports, so operating system implement a Data structure called segmentation to allocate 4 GB memory for each process , that is called virtual memory.

13. If Microprocessor permits to access 16MB RAM ,then the width of Address bus must be 24 bits

14. The half of the address 0XFFFFF is 0X7FFFF

This entry was posted in C Programming, Interview Q&A and tagged . Bookmark the permalink.