Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

History of C Language

Answer»

History of C LANGUAGE
As in introduction part we have clarified that C was developed by Dennis Ritchie in 1972 at bell laboratories of AT&T in U.S.A.

It was introduced to overcome the problems of its previous language such as B,BCPL etc.

Below are the list of PROGRAMMING language that comes before C Language:-
----Language--------Year-------------DevelopedBy-------
(1)Algol--------------1960------------INTERNATIONAL Group
(2)BCPL-------------1967------------Martin Richard
(3)B------------------1970------------Ken THOMPSON
(4)Traditional C----1972------------Dennis Ritchie
(5)K & R C----------1978------------Kernighan & Dennis Ritchie
(6)ANSI C-----------1989------------ANSI Committe
(7)ANSI/ISO C------1990------------ISO COmmitte
(8)C99---------------1999------------Standardization Committe

2.

Constants C

Answer»

Constants C
Constants USUALLY refer to fixed values that program MAY not be change during its execution. And these fixed value also CALLED literals. And constants can be any of the basic data which types is either integer, floating or character constant. And constant value or variable that we cannot changed in the program. And value can be 50,100,"a",3.4 or "crackyourinterview.com" etc. There are different types of constants in C programming.

List of Constants in C


Constant Value List

Different ways to define Constants in C


There are mainly 2 ways to define constant in C programming.
(1)CONST keyword
(2)#define preprocessor

(1)const keyword


The const keyword is used to define constant in C programming.
const float PI=3.14;

Now below example is the use of const variable PI


Constant Set Values
Output:-
The value of PI is: 3.140000


Another example which use to change contsant value


Constant Val Change
Output:-
COMPILE Time Error: Cannot modify a const object



(2)#define preprocessor


The #define preprocessor is also used to define constant.
Syntax:-
#define token value


Constant Define Value
Output:-
3.140000
3.

Install C Language

Answer»

Install C Language
There are so many compilers available for C and C++ these days. We can download any of them. Here in below example i have download Turbo C++. And this will work for both C and C++. Below are the steps to install that.
(1)Download Turbo C++
(2)Create a directory with turboc in C drive and we need to UNZIP tc3.zip INSIDE c drive c: turboc
(3)Now we need to double click on install.exe file
(4)Now click on tc application file which is locted inside C: TC Bin to write the C program.
Download Turbo C++
First download and unzip the file tc3.zip


Turbo C Download

It will ask you to install c or not, press enter to install.


Turbo C First Page

Change your drive to c and press c.


Turbo C location

look inside the c: turboc directory for the REQUIRED files


Turbo C Next

Select Start INSTALLATION by the down arrow KEY then press enter


Turbo C Images4

Now C is installed, press enter


Turbo C Options

Now open C Language


Turbo Last C

4.

Escape Sequence C

Answer» ESCAPE Sequence C
Escape Sequence is composed of two or more characters which starts with backslash (" "). Escape sequence in C is a sequence of characters that which doesn't REPRESENT itself when USED inside string literal or character. Below image helps you to get LIST of all Escape Sequence:-


Escape Sequence List

Escape Sequences Example




Escape Sequence Example
Output:-


Escape Sequence Output
5.

Format Specifier part2

Answer»

Format Specifier part2
As in part one i have SPECIFIED format specifier with some EXAMPLE and below are the left part for format specifier
(7)Use of %E in C program


Format Specifier %E
In above code output will be exponent part will be print and Exponentila is with capital E
Output:-
Exponential value of y is: 3.000000E+00


(8)Use of %g in C program


Format Specifier %g
In above code float value of y is display by using %g specifier. And %g will display the output same as the input with same precision.
Output:-
Float value of y is: 3.8


(9)Use of %p in C program


Format Specifier %p
In above code this will produce the hexadecimal form of some values
Output:-
Address value of y in hexadecimal form is: 0x7ffeb01a53ec


(10)Use of %c in C program


Format Specifier %c
In above code this will print value that CONVERT int value of char to ascii character.
Output:-
Value of a is: c


(11)Use of %s in C program


Format Specifier %s
In above code this will print value as string.
Output:-
CrackYourInterview


(12)Minimum Field Width Specifier


Format Specifier <klux>SPACE</klux>
In above code we use "%8d" specifier displays the value after 8 spaces while %-8d specifier will make a value left-aligned.
Output:-
900
900


(13)Field Empty Space


Format Specifier SpaceFill
In above code we will fill empty space with some other characters
Output:-
000000012


(14)Use of (Dot) operator


Format Specifier Dot
In above code we use dot operator with code
Output:-
12.20

6.

Format Specifier C

Answer»

Format Specifier C
Format specifier is string which is used in formatted input and output functions. And we use format string determines the format of input and output. Format string always starts with a "%" character.

Below are the most commonly used format SPECIFIERS in and printf() and scanf() function are GIVEN below.


Format Specifier C

EXAMPLE for Format Specifier


(1)Use of %d in C program


Format Specifier %dIn above example we use %d to print integer value of x and y

Output:-
Value of x is:2
Value of y is:4


(2)Use of %u in C program


Format Specifier %uIn above program we use %u to display value of x and y by USING unsigned format specifier. Here value of x is positive and for negative value it not print value of c and will change the value of -10.

Output:-
Value of x is:10
Value of y is:4294967286


(3)Use of %o in C program


Format Specifier %oIn above program we will get value of octal and integer for a specific common value.

Output:-
Octal Value of x is:100
Integer Value of x is:64


(4)Use of %X and %x in C program


Format Specifier %xXIn above code y contains the hexadecimal value "A" and it is shown in two format ONE is "a" and another is "A" which is smaller and capital X. ANd when we use %d then it is shown in integer values.

Output:-
Hexadecimal Value of y is:a
Hexadecimal Value of y is:A
Integer Value of y is:10


(5)Use of %f in C program



Format Specifier %fIn above code will print value of y as floating upto 6 characters

Output:-
Floating point value of y is: 3.400000


(6)Use of %e in C program


Format Specifier %eIn above code output will be exponent part will be print

Output:-
Exponential value of y is: 3.000000e+00
7.

C Keyword

Answer»

C KEYWORD
As all of language have some predefined keyword C also have. There are list of reserved WORD which can not be used as variable name.You cannot use it as a variable name, constant name, etc. There are pre-defined 32 reserved words (keywords) in C language.
Below SCREEN will help you to get these 32 keywords:-


Keyword Of C

8.

C Data Types

Answer»

C Data Types
Data Types specifies which types of values are we define. Usually we used Data Types with variables which significance that which types of values this variable store.
Here i have DIVIDED the data types in 4 categories as per given below:-


Data Type In C
(1)Basic Data Type:-int, char, float, DOUBLE
(2)Derived Data Type:-array, POINTER, structure, union
(3)Enumeration Data Type:-enum
(4)Void Data Type:-void

Here we have define only Basic Data Type. Basic data type are integer-based and floating-point based. C language supports both signed and unsigned literals. Memory size will be chagne ACCORDING to 32 to 64-bit OPERATING system. Below information will helps to get details as per 32-bit architecture.


Data Type Int Size

9.

printf() and scanf()

Answer»

printf() and scanf()
Most common USED functions in C LANGUAGE is printf() and scanf(). Both of these are inbuilt library functions which is defined in stdio.h which is header file. And printf() and scanf() function are used for input and output in C Language.

printf() function


We used printf() function for output. And it will prints the given statement to the console. And below is the syntax of printf() function is given below:-


Printf statement
The above formatstring can be %d, %c, %s and %f. Here we use %d for integer %c for character %s for string and %f for floats.

scanf() function


We used scanf() function for input in C language. It basically reads the DATA input from the console.



scanf statement

Program to print square of any NUMBER


Here in below example we gets input from user by scanf() function and after that we do square of number is print on console by printf() function



Square Program in C

Output:-


input your number: 10
square of number is: 100


The scanf("%d",&number) statement reads integer number from the console and stores the given value in number variable.

The printf("square of number is:%d ",number*number) statement prints the square of number on the console.

Program to print sum of two number


Here in below example we have intialize 3 integer variable as int and in 2 we take input and 3rd one is store the result then we will print the 3rd variable with printf function



Program of sum in C

Output:-


Input FIRST number: 8
Input second number: 9
Sum of 2 number is: 17
10.

Compilation in c

Answer»

Compilation in c
For new developer we must give a simple definition of compilation process. When we write program in C language first of all we will compile it. The compilation is the process to convert source code into object code. And this is done with the help of the compiler. First of all compiler checks the source code for the syntactical or structural errors and if it is error prone then it will create object code.



Compilation in C

This object code is also called machine code which is easily understand by machine. And this compilation process is basicaly divided in 4 steps as given below
(1)Pre-processing or Preprocessor
(2)COMPILING or Compiler
(3)Assembling or Assembler
(4)Linking or Linker




Compilation Process

(1)Preprocessor:-First we learn what is source code. Code we write in text editor in C langauge it is called source code. And the extension of this file is ".c". When we compile it then it is first passed to the preprocessor. Processor EXPAND the code and then pass this expand code to the compiler.

(2)Compiler:-When code is expanded by the preprocessor and passed to compiler. Compiler will converts code into assembly code. Or another way we can say C compiler converts the pre--prcoessed code into assembly code.

(3)Assembler:-Here assembly code is now converted into object code by using an assembler. The name of the object file generated by the assembler is the same as the source file. If the name of the source file is 'test.c', then the name of the object file would be "test.obj".

(4)Linker:-All program we written in C use library functions. And these library functions are pre-compiled and object code are stored with ".lib" or ".a" extension. The main working of the linker is to combine the object code of library FILES with the object code of our program. The output of the linker is the executable file. The name of the executable file is the same as the source file but differs only in their extensions. In DOS, the extension of the executable file is ".exe", and in UNIX, the executable file can be named as "a.out".




Compilation 4 steps

In above flow figure below are the differen steps:-
(1)Firstly we will pass test.c file to proprocessor then it converts the source code into the expanded source code. And the extension of expanded source code would be test.i.
(2)When expanded source code passed to compiler and compiler will converts the expanded source code into assembly code. And extension of assembly code would be test.s.
(3)Assembly code sent to assembler which converts the assembly code into object code. And extension is test.obj.
(4)After creating object code linker creates the executable file. And loader will then load the executable file for the EXECUTION.

11.

Start C Program

Answer»

Start C Program
Before going hard on program and logic i have created a simple program and PROVIDE details how to compile and run the first C program. To write our first program we need to open the C console and write the below CODE:-


First C Program
Now i will explain above code line by line. In above code first line is #include < stdio.h> . This will includes the standard input OUTPUT library functions. And there are lots of other includes files which we will be used later on. And printf() function is defined in stdio.h which we have used in above 3rd line.

Now comes to 2ND line which is function int main() here int is return type means it will return the integer values in above program we use "return 0" which means this will return 0. And now main() it is the main entry point of every program in C language.

Now 3rd line which i have allready explain it is used to print data on the console here in above program it will print "Hello C" on the console.

Now 4th line i have allready define it is used to return some values and here 0 value is used for successful execution and 1 for unsucessful execution. It is also known as the status to OS.

Now comes to compile and run the C Program>
We have 2 ways to compile and run c program one by the menu and another one is by shortcut
(1)CLICK on the compile menu then compile sub menu to compile c program. After that click on run menu then run sub menu to run aprogram in C.
(2)Second method is to clock Ctrl+F9 to both compile and run the program directly.

And below is the output screen for the above program



Run C Program

key Ctrl+F5 is also used to view the screen any time.

12.

C Comments

Answer»

C COMMENTS
Comments are used to provide some information about lines of code. Which helps developer to understand later on why this code is written or do some other information BIND with that code. Or in another language we can say that it is widely used for documenting code. There are 2 TYPES of comments in C language.
(1)Single Line Comments
(2)Multi-Line Comments

(1)Single Line Comments

Here in Single Line Comments which is REPRESENTED by double slash . In below EXAMPLE we have given example for single line comments.


C Single Comments
Output:-
Hello Welcome

Here in above code we can also add comments in single line with code too as given below


C Comments Code

(2)Multi Line Comments

Here we will write multi line comments which is represented by slash asterisk * ..... * . Here this will occupy many lines of code. But it will not have nested syntax.


MultiLine Comments
Output:-
Hello Welcome
13.

Features of C

Answer»

Features of C
C is most widely used language. And below are the 10 most features of C. Below figure will clarify the features.


C Feature
(1)Simple:-C is simple language and provides structured approach which breaks PROBLEM into parts that makes it too simple.
(2)Portable:-We can say C is portable or Machine Independent. C is not like Assembly Language as c program can be executed on different machines by doing some machine specific changes. Therefore its shows C is machine independent language.
(3)Mid-level PROGRAMMING language:-Although we said C is intended to low-level programming. We use C to develop system application like kernel, driver, etc. And it is also supports the features of high-level language. SO it is called mid-level language.
(4)Structured programming language:-We can break the program into parts using FUNCTIONS.
(5)Rich Library:-C provides LOT of inbuilt functions that make the development fast.
(6)Memory Management:-It will supports feature of dynamic memory allocation. In C we can free the allocated memory at any time by calling free() function.
(7)Speed:-compilation and execution time of C language is fast becuase there is less inbuilt function hence will have less OVERHEAD.
(8)Pointer:-One of the feature of C is pointer. We can directly interact with the memory by using the pointers. We can use pointers for memory, structures, functions, array, etc.
(9)Recursion:-C provides code reusability for every function. Recursion enables us to use the approach of backtracking.
(10)Extensible:-It is extensible because it can easily adopt new features.

14.

ASCII Value C

Answer»

ASCII Value C
ASCII full form is American Standard Code for Information Interchange. It is a character encoding scheme which is basically used for electronics communication. Here each character or special character is represented by some ASCII code and here each ascii code will occupies 7 bits in memory.
When we say about C programming language a character variable does not CONTAIN a character value of itself rather the asciii value of the character variable. ASCII value represents the character variable in numbers, and each character variable is assigned with some number range from 0 to 127. To understand this a example of ascii value of "A" is 65.
ASCII value of "A" is 65 so 65 will be stored in the character variable rather than "A".

Example for ASCII Character Input and Output

ASCII Values C
In above example PROGRAM will display ascii value of the charcter variable that we have input in the screen. First user will give the character input then values of that value get stored in the "ch" variable. Then after that it will print value of "ch" variable by USING %c format specifier and it will display "A" because we have given the charcter input as "A". If we use %d as format specifier then ascii value will be displayed as 65.

Output
Enter a characterA

The ascii value of the ch variable is : 65


Example for ASCII Character from 0-255 value of all characters


ASCII Values List
In above program this will print ascii value of all characters from 0 to 255 through the for loop.


Example for ASCII Character for Given input


ASCII Input Values
In above code we will TAKE input from user and then convert all character from input to ASCII values. And this will also provide the sum of all character of string in "sum" variable.
15.

C Variables

Answer»

C Variables
Variable are use to store data and its value can be changed as well as it can be reused many times as we wants. Or we also can say that variable is a name of memory location.

We can also say that it is the way to represent memory location through symbol so that it can be easily identified.

Below is the syntax to define the variable:-

<B>type variable_name;

And below is the example to declare variable:-


int x;
float y;
CHAR z;


Here in above x,y,z are variables. And int, float, char are different data types.

We can also set the value to the variable as per given below syntax:-


int x=10,n=20; //declare 2 varible in single line with values
float y=10.98;
char z='A';



Rules to define variables


Below are 4 most important rules when defining variables in C language:-
(1)We can use alphabets, digits and underscore.
(2)We can start variable with alphabet and underscore only. But it cannot start with a digit.
(3)We cannot use WHITESPACE in variable name.
(4)we cannot use variable name that is reserved WORD or keyword like int,float, char etc.

valid variable names:-
int a;
int _xyz;
int x20;

Invalid variable names:-
int 2;
int a b;
int long;
16.

Variables Types in C

Answer»

Variables Types in C
As per i define below there are 5 types of variables available in C:
(1)local variable
(2)global variable
(3)static variable
(4)automatic variable
(5)external variable

(1)Local Variable


When we declared variable inside the function or block is called a local variable. And we usually declared at the start of the block.


Local Variable
We must have to initialize the local variable before it is used.


(2)Global Variable


When we declared variable outside function or block is called global variable. And any of function can change value of global variable. And it is available to all the functions. And we usually define at the start of the block.



Global Variable

(3)Static Variable


When we declare variable with static keyword is called static variable. It retains its value between multiple function calls.


Static Variable
If we call function many times the local variable will print the same value for each and every function. In above EXAMPLE local variable alwasy remains 11. But when we declare static variable then it will be incremented in each function call 11,12,13 and so on.

(4)Automatic Variable


All variables in C that are declared inside the block, are automatic variables by default. We can explicitly declare an automatic variable using auto keyword.


Auto Variable

(5)External Variable


When we need to share a variable in multiple C source file then we need to use exteranl keyword. Below is the example to declare the EXTERN variable.
Below we have define two file ONE to declare external variable. and in 2nd file we use external variable .


Extern Variable
17.

C Identifiers

Answer»

C Identifiers
C identifiers will represent the name in c program and that names should be used for variables, functions, arrays, structures, unions and labels etc. And this identifiers can be composed of letters in both upper and lowercase, underscore and digits. But start should be either from composed of letters or by underscore. We cannot start this from digits that is incorrect. If identifier is not used in external linkage then it is called as an internal identifier. And in OPPOSITE if we used identifier is used in extrenal linkage then it is called external identifier.
There are 52 aplhabetical characters (26 for lower and 26 for uppercase), underscore character and ten numerical digits (0-9) which represnet the identifiers. There is a TOTAL of 63 alphanumerical characters that represent the identifiers.

Rules for create C identifiers

Below are the mainly 7 rules for creating a c identifier these are given below:-
(1)First character of an identifier should be either an ALPHABET or an underscore and then it is followed by any of the character, digit or underscore.
(2)We cannot use numerical digit as first character or we cannot we cannot start this from alphanumeric.
(3)We cannot use commas or blank spaces within an identifiers.
(4)We cannot use keywords as an identifier.
(5)There is LIMIT on identifiers and should not be more than 31 characters.
(6)When we ask about identifiers both uppercase and lowercase are distinct. So we can say that identfiers are case sensitive.
(7)We must write identifiers in such way that it is meaningful , short and easy to read and view.

Valid identifiers Example
totalval,sum,_a_,sum_1,average,view_1_d etc.

Invalid identifiers Example
2sum (cannot start with numerical digit)
int (Its a reserved word)
char (Its a reserved word)
m+n (Invalid character used "+")


Types of identifiers

(1)Internal Identifier
(2)External Identifier
(1)Internal Identifier:-As i have define above identifier that is not used in external linkage is known as internal identifier. And internal identifiers can be a local variables.
(2)External Identifier:-This is ALSO define above when identifier is used in the external linkage then its known as an external identifier. Example of external identifiers can be a function name or we can say a global variables.



Keyword and Identifier Difference


There are mainly 5 main differences between keyword and identifier are given below:-
(1)Keyword is pre-defined word and identifier is user-define word.
(2)Keyword must be written in lowercase letter and identifier can be written in both lowercase and in uppercase letters.
(3)Keyword cannot contain the underscore character but identifiers can contain underscore.
(4)Keyword meaning is pre-define in C compiler but identifier cannot be define in the c compiler.
(5)Keyword is combination of alphabetical characters and identifier is combination of alphanumeric characters.

Example of Identifier are case sensitive


Identifiers Example
Output of above code:-
Value of a is : 10
Value of A is :20

In above example and output we have shows that value of both variable "a" and "A" are different that shows that identifiers are case sensitive.
18.

C Operators

Answer»

C Operators
There are so many types of operations thats are arithmetic, logical, BITWISE etc. We use operator to perform different operations. There are following 8 types of operators which is used to operation in C LANGUAGE.
(1)Arithmetic Operators
(2)Relational Operators
(3)Shift Operators
(4)Logical Operators
(5)Bitwise Operators
(6)Ternary or Conditional Operators
(7)Assignment Operator
(8)Misc Operator

Precedence of Operators in C


Precedence of operator species that which operator will be evaluated first and next. Here associativity specifies the operator direction to be evaluated and it may be left to RIGHT or right to left.

Below is the example which help us to understand the Precedence of Operators

int value=10+30*10;

The value variable will contain 310 here because (multiplicative operator) is evaluated before + (additive operator).

The precedence and associativity of C operators is given below:


Operator In C
19.

Introduction to C

Answer»

Introduction to C
C is the most Popular Language for beginners. C is a PROCEDURAL programming language. The C Language is developed by Dennis Ritchie in Year 1972. C programming language mainly developed as system programming language for writing an OPERATING system. Many of C language Feature makes C language suitable for system programming like Low-Level access to memory, Simple set of Keyword and Clean style.

Many of the popular language take syntax from C and these language are Java, PHP, JavaScript and many more. So it is known as mother language. C++ is superset of C Language.

Below are the different definition for C language:-
(1)Mid-Level programming Language
(2)Structured programming Language
(3)System Programming Language
(4)Procedure-oriented programming Language
(5)Mother Language