1. What is C language?

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. 

Uses:

  • Operating system development

  • Compilers and Assemblers

  • Network drivers

  • Interpreters

2.printf() Function.
What is the output of printf(“%d”)?

In C programming language, printf() function is used to print the (“character, string, float, integer, octal and hexadecimal values”) onto the output screen and returns the number of characters it successfully prints on the console. 

The output of printf(“%d”) is garbage.

3. What is the difference between “calloc(…)” and “malloc(…)”?

The name malloc and calloc() are library functions that allocate memory dynamically. It means that memory is allocated during runtime(execution of the program) from the heap segment.

malloc() in C
“malloc” or “memory allocation” method in C is used to dynamically allocate a single large block of memory with the specified size. It returns a pointer of type void which can be cast into a pointer of any form. It initializes each block with default garbage value.

Syntax:
ptr = (cast-type*) malloc(byte-size);

For Example:
ptr = (int*) malloc(100 * sizeof(int));

Since the size of int is 4 bytes, this statement will allocate 400 bytes of memory. And, the pointer ptr holds the address of the first byte in the allocated memory.

calloc() in C
“calloc” or “contiguous allocation” method in C is used to dynamically allocate the specified number of blocks of memory of the specified type. It initializes each block with a default value ‘0’.

Syntax:
ptr = (cast-type*)calloc(n, element-size);

For Example:
ptr = (float*) calloc(25, sizeof(float));

This statement allocates contiguous space in memory for 25 elements each with the size of the float.

4. printf() Function- What is the difference between “printf(…)” and”sprintf(…)”?
sprintf(…) writes data to the character array whereas printf(…) writes data to the standard output device.

5. Compilation How to reduce a final size of executable?
Size of the final executable can be reduced using dynamic linking for libraries.

6. POP(Procedural Oriented Programming Language) Vs OOP(Object Oriented Programming Language).

POP(Procedural Oriented Programming Language)
a.Structure oriented.
b.Program is divided into function.
c.Top-down approach.
d.Inheritence is not allowed.
e.It does not use access specifier.
f.No data hiding.
g.No virtual function.
h.Example:C,Pascal.


OOP(Object Oriented Programming Language)
a.Object oriented.
b.Program is divided into object.
c.Bottom-up approach.
d.Inheritance property is used.
e.It uses access specifier.
f.Encapsulation is used to hide data.
g.Concept of virtual data.
h.Example:C++,Java.

 

7. What is token in C?

Each and every smallest individual unit in C program are known as C tokens.

C tokens are of six types. C supports following tokens:
1.Keywords: Words which are specific to the C language.[Ex- int,while]
2.Identifiers: User defined names/abbreviations. [Ex- main,total]
3.Constants:Values which dont change.[Ex-10,20]
4.Strings: Sequence of characters.[Ex-“hello”,”c program”]
5.Operators: Act on operands and generates output.[Ex: +,-,/,*]
6.Special symbols:[Ex- (),{},#]

8. What is keywords?

All keywords are basically the sequences of character that have a particular meaning.
a. Keywords are reserved words.[It must have special meaning]
b. In c there are 32 keywords.
c. All keywords are written in lowercases.
Example: int,default,while,break,continue.

9. How many keywords in C?

32.

10. What is constants?

Fixed values that do not change during execution of a C program.

Constants:- i)Numeric Constants[a)Integer,b)Real]
ii)Character Constants[a)Single Character Contants,b)String Contants]

11. Types of operator in C?

  1. Arithmetic operators

  2. Relational operators

  3. Logical operators

  4. Bitwise operators

  5. Assignment operators

  6. Conditional operators

  7. Special operators

  8. Unary Operator

12. Character array Vs string.

13. Datatype in c.

i)Datatypes in C language are defined as the data storage format that a variable can store data to perform a specific operation.
ii)Datatypes are used to define a variable before using it in a program.
iii)Size of variable, constant, and array are determined by data types.
Example:char,int,short,long.

14. Size of the datatype.

char:1 byte,int:2/4 bytes,short:2 bytes,long:8 bytes.

15. Types of Error?

a)Syntax Error: Violation of grammar, missing brackets, missing semicolon(;).
b)Logical Error: Errors occur during the coding process.
c)Runtime Error: Error occurs when we attempt to run the ambiguous instruction. Like b=0; when c=a/b;

16. Decision making and branches statement in C?

C has three major decision making-
i)simple if statement.
ii)if-else.
iii)if-else-if later.
iv)switch.
v)Using conditional operator/ternary.

17. Difference b/w three-loop in c.

18. Break vs continue vs exit.

19. Example of Break Statement.

20. Example of Continue statement.

21. Example of Exit Statement.

22. goto statement and limitation/disadvantage.

goto statement is used to transfer the normal flow of a program to the specified
label in the program.
Syntax:
{

goto label;
……
……
LABEL:
statements;
}


There are two types of jump in goto statement:
1. Forward jump
2. Backward jump
goto makes the program logic very complex
goto should be avoilded

23. Storage class in C?

A storage class defines the scope and life-time of variables and/or functions within a C program.They
precede the type that they modify.We have four different storage classes in a C program-
i)auto-The auto storage class is the default storage class for all loacl variables.
{
int mount;
auto int month;
}
ii)register: The register storage class is used to define local variables that should be stored in a register instead of RAM. This means that the variable has a maximum size equal to the register size and can’t have the unary ‘&’ operator applied to it(as it does not have a memory location).
{
register int miles;
}
iii)Static: The static storage class instructs the compiler to keep a local variable in existence during the
a life-time of the program instead of creating and destroying it each time it comes into and goes out of scope.
Therefore, making local variables static allows them to maintain their values between function calls.
iv)extern: The extern storage class is used to give a reference to a global variable that is visible to all the
program files. When you use ‘extern’, the variable cannot be initialized however, it points the variable name at a
storage location that has been previously defined.

24. Local variable, Global variable, Constant variable.

i)Local variable:
a.The variables which are having scope/life only within the function are called local variables.
b.This variables are declared within the function and can’t be accessed outside the function.
ii)Global variable:
a.The variable which is having scope/life throughout the program are called global variables.
b.Global variable is defined outside the main function. So, this variable is visible to the main function
and all other functions.
iii)Constant Variable: Variables can be declared as constants by using the “const” keyword before the data type
of the variable. The constant variables can be initialized once only. The default value of the constant variable is
zero. A program that demonstrates the declaration of constant variables in C using the const keyword is given as follows.

25. What is an Array?

i)An array in a collection of elements of similar datatype which are stored in contiguous
memory locations.
ii)Every element in an array has a specific index.
iii)Size of array is fixed at the time of definition.
Syntax: int a[10]; //single dimensional array.
int a[10][10];//double dimensional array. 

26. What is a function?

a.Functions are blocks of code which are used to perform specific tasks.
b.In C a function needs to be declared before its used.
c.Functions have a function definition,function body and a return type.
d.Functions with return type not as void need to return a value at the end.
e.Functions with return type void do not return any value.

27. Types of function in C?

There are two types of functions in C.
1.Built-in(library) Functions:
i)The system provided these functions and stored in library. Therefore it is also called library functions.
Ex: scanf(),printf(),strcpy.strlwr,strcmp,strlen,strcat etc.
ii)To use these functions,you just need to include the appropriate C header files.
2.User Defined function: These functions are defined by the user at the time of writing the program.

28. What in pointer in C?

Pointer is a variable that holds the address of another variable.

Syntax: int a=10;
int *p = &a;