Curriculum
- 8 Sections
- 119 Lessons
- 25 Weeks
Expand all sectionsCollapse all sections
- Course Overview/*! CSS Used from: Embedded */ *, ::after, ::before { box-sizing: border-box; border-width: 0; border-style: solid; border-color: #e5e7eb; } ::after, ::before { --tw-content: ''; } h2 { font-size: inherit; font-weight: inherit; } a { color: inherit; text-decoration: inherit; } h2, p { margin: 0; } :disabled { cursor: default; } *, ::before, ::after { --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-scroll-snap-strictness: proximity; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgb(59 130 246 / 0.5); --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; } .mx-auto { margin-left: auto; margin-right: auto; } .mb-2 { margin-bottom: 0.5rem; } .mb-4 { margin-bottom: 1rem; } .mb-6 { margin-bottom: 1.5rem; } .mr-2 { margin-right: 0.5rem; } .max-w-screen-sm { max-width: 640px; } .max-w-screen-xl { max-width: 1280px; } .rounded-lg { border-radius: 0.5rem; } .bg-primary-700 { --tw-bg-opacity: 1; background-color: rgb(29 78 216 / var(--tw-bg-opacity)); } .bg-white { --tw-bg-opacity: 1; background-color: rgb(255 255 255 / var(--tw-bg-opacity)); } .px-4 { padding-left: 1rem; padding-right: 1rem; } .px-5 { padding-left: 1.25rem; padding-right: 1.25rem; } .py-2.5 { padding-top: 0.625rem; padding-bottom: 0.625rem; } .py-8 { padding-top: 2rem; padding-bottom: 2rem; } .text-center { text-align: center; } .text-4xl { font-size: 3rem; line-height: 2.5rem; } .text-sm { font-size: 0.875rem; line-height: 1.25rem; } .font-extrabold { font-weight: 800; } .font-light { font-weight: 300; } .font-medium { font-weight: 500; } .leading-tight { line-height: 1.25; } .tracking-tight { letter-spacing: -0.025em; } .text-gray-500 { --tw-text-opacity: 1; color: rgb(107 114 128 / var(--tw-text-opacity)); } .text-gray-900 { --tw-text-opacity: 1; color: rgb(17 24 39 / var(--tw-text-opacity)); } .text-white { --tw-text-opacity: 1; color: rgb(255 255 255 / var(--tw-text-opacity)); } .hover\:bg-primary-800:hover { --tw-bg-opacity: 1; background-color: rgb(30 64 175 / var(--tw-bg-opacity)); } .focus\:outline-none:focus { outline: 2px solid transparent; outline-offset: 2px; } .focus\:ring-4:focus { --tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color); --tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(4px + var(--tw-ring-offset-width)) var(--tw-ring-color); box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000); } .focus\:ring-primary-300:focus { --tw-ring-opacity: 1; --tw-ring-color: rgb(147 197 253 / var(--tw-ring-opacity)); } @media (min-width: 640px) { .sm\:py-16 { padding-top: 4rem; padding-bottom: 4rem; } } @media (min-width: 768px) { .md\:text-lg { font-size: 1.5rem; line-height: 1.75rem; } } @media (min-width: 1024px) { .lg\:px-6 { padding-left: 1.5rem; padding-right: 1.5rem; } } .imgdata { width: 35% } @media (max-width: 767px) { .imgdata { width: 40% } } .course-payment { display: none !important; } .thim-course-landing-button { display: none !important; }0
- NumericalTCS-NQT Instructions : You will be given 26 Question with a time limit of 40 mins | Questions - 26 | Time - 40 mins48
- 2.1Profit and Loss [ Notes ]
- 2.2Profit & Loss [Formula]
- 2.3Profit and Loss [Practice Problems]
- 2.4Geometry Formula and Concept
- 2.5Geometry Formula and Concept [Practice problem]
- 2.6HCF and LCM [ Handmade Notes ]
- 2.7HCF and LCM [ Formula ]
- 2.8HCF and LCM [ Practice Problems ]
- 2.9Percentage Problem [Formula]
- 2.10Percentage Problem [ Notes ]
- 2.11Percentage Problem [Practice Problems]
- 2.12Alligation and Mixtures [Formula]
- 2.13Alligation and Mixtures [Handmade Notes]
- 2.14Alligation and Mixtures [Practice Problems]
- 2.15Time and Work[Formula]
- 2.16Time and Work [Handmade Notes]
- 2.17Time and Work [Practice Problems]
- 2.18Ages [ Formula ]
- 2.19Ages Problem [Handmade Notes]
- 2.20Ages Problem [Practice Problems]
- 2.21Sequence and Series
- 2.22Sequence and Series [Practice problem ]
- 2.23Divisibility
- 2.24Divisibility [Practice problem ]
- 2.25Ratio and Proportion
- 2.26Ratio and Proportion [Practice problem ]
- 2.27Probability [ Formula and Solved Examples ]
- 2.28Probability [Practice problem ]
- 2.29Perimeter, Area and Volume
- 2.30Perimeter, Area and Volume [Practice problem ]
- 2.31Your Feedback Means Alot to Us ❤️2 Minutes
- 2.32Average Formula and Concept
- 2.33Average Formula and Concept [Practice problem ]
- 2.34Speed Time And Distance
- 2.35Speed Time And Distance [Practice problem ]
- 2.36Mean Median Mode
- 2.37Mean Median Mode [Practice problem ]
- 2.38Decimals and Fractions
- 2.39Decimals and Fractions Formula [Practice problem ]
- 2.40Pie Chart
- 2.41Pie Chart Practice Problem
- 2.42Bar Chart
- 2.43Bar Chart Practice Problem
- 2.44Your Feedback Means Alot to Us ❤️2 Minutes
- 2.45Profit and Loss [Notes]
- 2.46Percentage Problem [Notes]
- 2.47Ratio and Proportion [Notes]
- 2.48Average [Notes]
- VerbalTCS-NQT Instructions : You will be given 24 Question with a time limit of 30 mins | Questions - 24 | Time - 15 mins + 30 mins10
- 3.1Sentence Completion [ Notes + Solved Examples + Practice Problem ]
- 3.2Spotting Erorrs [ Notes + Solved Examples + Practice Problem ]
- 3.3Reading Comprehension [ Notes + Solved Examples + Practice Problem ]
- 3.4Meanings [ Notes + Solved Examples + Practice Problem ]
- 3.5Tenses [ Notes + Solved Examples + Practice Problem ]
- 3.6Idioms And Phrases [ Notes + Solved Examples + Practice Problem ]
- 3.7Formal And Informal Sentences
- 3.8Formal And Informal Sentences [Practice problem]
- 3.9Sentence Arrangement
- 3.10Sentence Arrangement [Practice problem]
- Aptitude Series for Placement [ Free Sample Videos ]Note: TCS NQT Study Material Doesn't Contain videos we provide only Study Materials in this course , these videos are sample videos of our Aptitude Series16
- 4.1📌 Watch this Video to Crack your Aptitude2 Minutes
- 4.2Train Problems Part #119 Minutes
- 4.3Train Problems Part #211 Minutes
- 4.4Train Problems Part #319 Minutes
- 4.5Train Problems [Handmade Notes]
- 4.6📌 Practice Problems [Quiz] – Train Problems
- 4.7Calendar Basics13 Minutes
- 4.8📌 Take the Complete Aptitude Series Now [ Videos Lectures – Quant , Verbal and Reasoning ] 📌
- 4.9Calendar Problem [Handmade Notes]
- 4.10📌 Practice Problems [Quiz] – Calendar
- 4.11Time and Work Part #120 Minutes
- 4.12Time and Work Part #213 Minutes
- 4.13Time and Work Part #312 Minutes
- 4.14Time and Work [Handmade Notes]
- 4.15📌 Practice Problems [Quiz] – Time and Work
- 4.16📌 Take the Complete Aptitude Series Now [ Videos Lectures – Quant , Verbal and Reasoning ] 📌
- ReasoningTCS-NQT Instructions : You will be given 30 Question with a time limit of 50 mins | Questions - 30 | Time - 50 mins21
- 5.1Blood Relation [ Formulas + Notes ]
- 5.2Blood Relation [ Practice Problem ]
- 5.3Number Series [ Formulas + Notes ]
- 5.4Number Series [ Practice Problem ]
- 5.5Seating Arrangement [ Formulas + Notes ]
- 5.6Seating Arrangement [ Practice Problem ]
- 5.7Syllogism [ Formulas + Notes ]
- 5.8Syllogism [ Practice Problem ]
- 5.9Data Sufficiency [ Formulas + Notes ]
- 5.10Data Sufficiency [ Practice Problem ]
- 5.11Clocks [Formula]
- 5.12Clock Problem [Handmade Notes]
- 5.13Clock Problem [Practice Problems]
- 5.14Calendar Problem [Formula]
- 5.15Calendar Problem [Handmade Notes]
- 5.16Calendar Problem [Practice Problems]
- 5.17Number Series [Notes]
- 5.18Syllogism [Notes]
- 5.19Clock Problem [Notes]
- 5.20Coding decoding [Notes]
- 5.21Coding decoding [Practice problem]
- Programming LogicTCS-NQT Instructions : You will be given 10 Question with a time limit of 15 mins | Questions - 10 | Time - 15 mins6
- CodingTCS-NQT Instructions : You will be given 2 Question with a time limit of 15 mins and 30 mins | Questions - 2 | Time - 15 mins + 30 mins16
- 7.1Introduction to java
- 7.2[Programs] Introduction To Java
- 7.3Flow Control
- 7.4[Programs] Flow Control
- 7.5[Programs] Pyramids & Patterns
- 7.6Arrays
- 7.7[Programs] Arrays
- 7.8Java Methods, Class & Object
- 7.9[Programs] Java Methods, Class & Object
- 7.10Strings, Recursion, Modifiers & Keywords
- 7.11[Programs] Strings, Recursion, Modifiers & Keywords
- 7.12Object-Oriented Programming System
- 7.13[Programs] Object Oriented Programming System
- 7.14Exception Handling & Files
- 7.15[Program] Exception Handling & Files
- 7.16TCS-NQT Mock Coding Questions
- Previous Year Paper and Solution2

Basic of C
➢ Basic Data Types
Like before learning any language first we learn its alphabets then words then
sentence and finally paragraphs. So, before learning C language we have to
learn its alphabets.
1. Character (char)
✔ Size is 1 bytes.
✔ Range: -128 to 127
✔ Example: a,b,c,d,e,f………….z,A,B,C,D,E etc
2.Integer (int)
✔ Size is 2 bytes.
✔ Range: −32,768 to 32,767
✔ Example: 1,2,-1,5,-100 etc.
3.Float(float)
✔ Size is 4 bytes.
✔ This have both integer as well as decimal part.
✔ Precision: 6 Decimal places.
✔ Example: 12.345 etc.
4.Double(double)
✔Size is 8 bytes.
✔This have both integer as well as decimal part.
✔Precision: 15 Decimal places.
✔Example: 12.3567863 etc.
5.long Double (long double)
✔Size is 10 bytes.
✔This have both integer as well as decimal part.
✔Precision: 19 Decimal places.
✔Example: 12.356786398765432678 etc.

Input-Output (based on C)
Input/Output In C
C Output
In C programming, printf() is one of the main output function. The function
sends formatted output to the screen. For example,
Example 1: C Output
#include <stdio.h>
int main()
{
// Displays the string inside quotations
printf("C Programming");
return 0;
}
Output
C Programming
How does this program work?
● All valid C programs must contain the main() function. The code
execution begins from the start of the main() function.
● The printf() is a library function to send formatted output to the screen.
The function prints the string inside quotations.
● To use printf() in our program, we need to include stdio.h header file
using the #include <stdio.h> statement.
● The return 0; statement inside the main() function is the "Exit status" of
the program. It's optional.
Example 2: Integer Output
#include <stdio.h>
int main()

{
int testInteger = 5;
printf("Number = %d", testInteger);
return 0;
}
Output
Number = 5
We use %d format specifier to print int types. Here, the %d inside the
quotations will be replaced by the value of testInteger.
Example 3: float and double Output
#include <stdio.h>
int main()
{
float number1 = 13.5;
double number2 = 12.4;
printf("number1 = %f\n", number1);
printf("number2 = %lf", number2);
return 0;
}
Output
number1 = 13.500000
number2 = 12.400000
To print float, we use %f format specifier. Similarly, we use %lf to print double
values.
Example 4: Print Characters
#include <stdio.h>
int main()
{
char chr = 'a';
printf("character = %c", chr);
return 0;
}
Output

character = a
To print char, we use %c format specifier.
C Input
In C programming, scanf() is one of the commonly used function to take input
from the user. The scanf() function reads formatted input from the standard
input such as keyboards.
Example 5: Integer Input/Output
#include <stdio.h>
int main()
{
int testInteger;
printf("Enter an integer: ");
scanf("%d", &testInteger);
printf("Number = %d",testInteger);
return 0;
}
Output
Enter an integer: 4
Number = 4
Here, we have used %d format specifier inside the scanf() function to take int
input from the user. When the user enters an integer, it is stored in the
testInteger variable.
Notice, that we have used &testInteger inside scanf(). It is because
&testInteger gets the address of testInteger, and the value entered by the user
is stored in that address.
Example 6: Float and Double Input/Output
#include <stdio.h>
int main()
{
float num1;
double num2;
printf("Enter a number: ");
scanf("%f", &num1);
printf("Enter another number: ");

scanf("%lf", &num2);
printf("num1 = %f\n", num1);
printf("num2 = %lf", num2);
return 0;
}
Output
Enter a number: 12.523
Enter another number: 10.2
num1 = 12.523000
num2 = 10.200000
We use %f and %lf format specifier for float and double respectively.
Example 7: C Character I/O
#include <stdio.h>
int main()
{
char chr;
printf("Enter a character: ");
scanf("%c",&chr);
printf("You entered %c.", chr);
return 0;
}
Output
Enter a character: g
You entered g
When a character is entered by the user in the above program, the character
itself is not stored. Instead, an integer value (ASCII value) is stored.
And when we display that value using %c text format, the entered character is
displayed. If we use %d to display the character, it's ASCII value is printed.
Example 8: ASCII Value
#include <stdio.h>
int main()
{
char chr;

printf("Enter a character: ");
scanf("%c", &chr);
// When %c is used, a character is displayed
printf("You entered %c.\n",chr);
// When %d is used, ASCII value is displayed
printf("ASCII value is %d.", chr);
return 0;
}
Output
Enter a character: g
You entered g.
ASCII value is 103.
I/O Multiple Values
Here's how you can take multiple inputs from the user and display them.
#include <stdio.h>
int main()
{
int a;
float b;
printf("Enter integer and then a float: ");
// Taking multiple inputs
scanf("%d%f", &a, &b);
printf("You entered %d and %f", a, b);
return 0;
}
Output
Enter integer and then a float: -3
3.4
You entered -3 and 3.400000
Format Specifiers for I/O

As you can see from the above examples, we use
●
%d for int
●
%f for float
●
%lf for double
●
%c for char
Here's a list of commonly used C data types and their format specifiers.

Functions and scope
★ Functions Basic
Till now we have been doing all the operations in the main() function only ,but
there may occur conditions where we have to perform the same operation many
times , every time then we will have to write the code of operation which will
make the program big and heavy(Ex. if we want
to apply matrix multiplication 4 times ,then it will be very cumbersome to write
the same code 4 times in the main() function). Instead of writing the same code
several time in the main() function we will make a new function performing the
same operation and call it inside main() function wherever we require it. A
function is a group of statements that together perform a task. Every C program
has at least one function, which is main(). Till now we have been using
functions like strlen(),strcat(),strrev() etc. all these are already defined in C
language ,but user defined function means a user will define a function of its
own.
Defining a Function
The general form of a function definition in C programming language is as
follows −
return_type function_name( parameter list ) {
body of the function
}
A function definition in C programming consists of a function header and a
function body. Here are all the parts of a function −
● Return Type − A function may return a value. The return_type is the
data type of the value the function returns. Some functions perform the
desired operations without returning a value. In this case, the return_type
is the keyword void.

● Function Name − This is the actual name of the function. The function
name and the parameter list together constitute the function signature.
● Parameters − A parameter is like a placeholder. When a function is
invoked, you pass a value to the parameter. This value is referred to as
actual parameter or argument. The parameter list refers to the type, order,
and number of the parameters of a function. Parameters are optional; that
is, a function may contain no parameters.
● Function Body − The function body contains a collection of statements
that define what the function does.
Example Program:-
Given below is the source code for a function called max(). This function takes
two parameters num1 and num2 and returns the maximum value between the
two −
/* function returning the max between two numbers */
int max(int num1, int num2) {
/* local variable declaration */
int result;
if (num1 > num2)
result = num1;
else
result = num2;
return result;
}
Function Declarations
A function declaration tells the compiler about a function name and how to call
the function.
The actual body of the function can be defined separately.
A function declaration has the following parts −
return_type function_name( parameter list );

For the above defined function max(), The function declaration is as follows
−
int max(int num1, int num2);
Parameter names are not important in function declaration only their type is
required,
so the following is also a valid declaration −
int max(int, int);
Function declaration is required when you define a function in one source file
and you call that function in another file. In such case, you should declare the
function at the top of the file calling the function.
Calling a Function
While creating a C function, you give a definition of what the function has to
do. To use a function, you will have to call that function to perform the defined
task.
When a program calls a function, the program control is transferred to the called
function. A called function performs a defined task and when its return
statement is executed or when its function-ending closing brace is reached, it
returns the program control back to the main program.
To call a function, you simply need to pass the required parameters along with
the function name, and if the function returns a value, then you can store the
returned value. For example −
#include <stdio.h>
/* function declaration */
int max(int num1, int num2);
int main () {
/* local variable definition */
int a = 100;
int b = 200;

int ret;
/* calling a function to get max value */
ret = max(a, b);
printf( "Max value is : %d\n", ret );
return 0;
}
/* function returning the max between two numbers */
int max(int num1, int num2) {
/* local variable declaration */
int result;
if (num1 > num2)
result = num1;
else
result = num2;
return result;
}
We have kept max() along with main() and compiled the source code. While
running the final executable, it would produce the following result −
Max value is : 200

Inbuilt Libraries
C Standard library functions or simply C Library functions are inbuilt functions in
C programming.
The prototype and data definitions of these functions are present in their
respective header files. To use these functions we need to include the header
file in our program. For example,
If you want to use the printf() function, the header file <stdio.h> should be
included.
#include <stdio.h>
int main()
{
printf("Catch me if you can.");
}
If you try to use printf() without including the stdio.h header file, you will get an
error.
Advantages of Using C library functions
1. They work
One of the most important reasons you should use library functions is simply
because they work.
2. The functions are optimized for performanceSince, the functions are
"standard library" functions, a dedicated group of developers constantly make
them better.
3. It saves considerable development time
Since the general functions like printing to a screen, calculating the square
root, and many more are already written.
4. The functions are portable
With ever-changing real-world needs, your application is expected to work
every time, everywhere.
Example: Square root using sqrt() function
Suppose, you want to find the square root of a number.
To compute the square root of a number, you can use the sqrt() library function.
The function is

defined in the math.h header file.
#include <stdio.h>
#include <math.h>
int main()
{
float num, root;
printf("Enter a number: ");
scanf("%f", &num);
// Computes the square root of num and stores in root.
root = sqrt(num);
printf("Square root of %.2f = %.2f", num, root);
return 0;
}
When you run the program, the output will be:
Enter a number: 12
Square root of 12.00 = 3.46
Library Functions in Different Header File

Variable and Register
Variables in C
Variable is like a container (storage space) with a name in which you can store
data.
It's like your home has an address (House No./Flat No.) so whenever you
order something online, you just have to provide your home address and the
delivery executive is able to find it.
In the C language, if we want to use some data value in our program, how
can we do it? Well, it's done using variable.
When we create a variable in a C program, the C compiler allocates a storage
space, depending upon the datatype of the variable(8 bits for char, 16/32 bits

for int, etc.), and then that storage space is given a name which is the variable
name.
Once a variable is created, we can store value in it. We can change the value
stored in a variable as many times as we want, but we should make sure we
store the correct data type value.
Syntax for using Variable:
Here is how you can create or declare a new variable in the C language,
data_type var_name;
where, data_type is a valid data type (along with data type modifiers, if
required) and var_name is the name of the variable.
For example,
int marks;
Here, marks is the name of the variable, and it can store values of int type.
Once we have declared or created the variable, then we can assign a value to
it. This is called variable definition.
// variable declaration
int marks;
// variable definition
marks = 10;
We can do declaration and definition in a single step too, like this
(recommended).
int marks = 10;
You can change the value of the variable, whenever you want. But make
sure the value is of correct data type.
// variable defined
int marks = 10;
// assign a new value
marks = 33;

Datatype of the Variable
A variable in C language must be given a type, which defines what type of
data can be stored in the variable. If you do not provide any datatype, then the
C compiler will give compile-time error or syntax error.
The datatype can be char, int, float, double, or short int, long int, etc. data type
along with modifiers.
Let's take an example,
// char type variable
char status = 'Y';
// int type variable
int marks = 95;
// float type variable
float percentage = 94.6;
// double type variable
double long = 76.997429;
If you try to assign an incorrect datatype value to a variable, then the
compiler may giver error, or it will automatically convert the value into the
datatype of the variable.
For example,
#include <stdio.h>
int main() {
// assign incorrect value
int x = 10.58;
printf("Value is %d", x);
return 0;
}
Value is 10
As you can see in the output, the C compiler removed the part after the
decimal, because int datatype can only store whole numbers.
We will learn about printf() function and %d (used to print the value of the int
datatype) in the next tutorial, with more code examples.

Datatype cannot be changed
Once we define a variable with some datatype then we cannot change the
datatype of that variable.
For example,
// int variable
int marks = 10;
float marks;
// error
Rules to name a Variable
When you create a variable, you should always give a meaningful name to the
variable. And follow the below rules for naming the variable:
1. Variable name must not start with a digit.
2. The variable name can consist of alphabets, digits, and special symbols
like underscore _.
3. Blank or spaces are not allowed in the variable name.
4. Keywords are not allowed as a variable name.
5. Upper and lower case names are treated as different, as C is
case-sensitive, so it is suggested to keep the variable names in lower
case.
Let's see a few examples for incorrect names as per the above rules:
int 1var;
// incorrect - should not start with number
int var1;
// correct
int my$var
// incorrect - special characters not allowed
int my_var1;
// correct
int my var;
// incorrect - spaces not allowed
char else;
// can't use Keywords
int count;
// valid variable name
int Count;
// new variable
int COUNT;
// new variable
Difference between Variable and Identifier?

An Identifier is a name given to any variable, function, structure, pointer, or any
other entity in a programming language. While a variable, as we have just
learned in this tutorial is a named memory location to store data that is used in
the program.
Another great analogy to understand the difference between Identifier and
Variable is:
You can think of an Identifier int x to be a variable's name, but it can also be a
function's name int x() { } and still, be an identifier.
Just like Obama is the name of a person, but also the name of a foundation.
Literals:
Literals are data used for representing fixed values. They can be used directly in
the code. For example: 1, 2.5, 'c' etc.
Here, 1, 2.5 and 'c' are literals. Why? You cannot assign different values to these
terms.
1. Integers
An integer is a numeric literal(associated with numbers) without any fractional
or exponential part. There are three types of integer literals in C programming:
● decimal (base 10)
● octal (base 8)
● hexadecimal (base 16)
For example:
Decimal: 0, -9, 22 etc
Octal: 021, 077, 033 etc
Hexadecimal: 0x7f, 0x2a, 0x521 etc
In C programming, octal starts with a 0, and hexadecimal starts with a 0x.
2. Floating-point Literals
A floating-point literal is a numeric literal that has either a fractional form or an
exponent form. For example:
-2.0
0.0000234
-0.22E-5

3. Characters
A character literal is created by enclosing a single character inside single
quotation marks. For example: 'a', 'm', 'F', '2', '}' etc.
4. Escape Sequences
Sometimes, it is necessary to use characters that cannot be typed or has special
meaning in C programming. For example: newline(enter), tab, question mark
etc.
In order to use these characters, escape sequences are used.
Escape
Character
Sequences
\b
Backspace
\f
Form feed
\n
Newline
\r
Return
\t
Horizontal tab
\v
Vertical tab
\\
Backslash
\'
Single quotation
mark

\"
Double quotation
mark
\?
Question mark
\0
Null character
For example: \n is used for a newline. The backslash \ causes escape from the
normal way the characters are handled by the compiler.
5. String Literals
A string literal is a sequence of characters enclosed in double-quote marks. For
example:
"good"
//string constant
""
//null string constant
" "
//string constant of six white space
"x"
//string constant having a single character.
"Earth is round\n"
//prints string with a newline
The register Storage Class
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 (usually one word) and can't have the
unary '&' operator applied to it (as it does not have a memory location).
{
register int miles;
}
The register should only be used for variables that require quick access such
as counters. It should also be noted that defining 'register' does not mean that
the variable will be stored in a register. It means that it MIGHT be stored in a
register depending on hardware and implementation restrictions.
The static Storage Class

The static storage class instructs the compiler to keep a local variable in
existence during the 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.
The static modifier may also be applied to global variables. When this is
done, it causes that variable's scope to be restricted to the file in which it is
declared.
In C programming, when static is used on a global variable, it causes only
one copy of that member to be shared by all the objects of its class.
#include <stdio.h>
/* function declaration */
void func(void);
static int count = 5; /* global variable */
main() {
while(count--) {
func();
}
return 0;
}
/* function definition */
void func( void ) {
static int i = 5; /* local static variable */
i++;
printf("i is %d and count is %d\n", i, count);
}
When the above code is compiled and executed, it produces the following
result −
i is 6 and count is 4
i is 7 and count is 3
i is 8 and count is 2
i is 9 and count is 1
i is 10 and count is 0

Command Line Programming
What are Command Line Arguments in C?
Command line arguments are nothing but simply arguments that are specified
after the name of the program in the system’s command line, and these
argument values are passed on to your program during program execution.
Components of Line Arguments
In order to implement command line arguments, generally, 2 parameters are
passed into the main function:
1. Number of command line arguments
2. The list of command line arguments
The basic syntax is:
int main( int argc, char *argv[] )
{
// BODY OF THE MAIN FUNCTION
}
Another way to implement command line arguments is:
int main( int argc, char **argv[] )
{
// BODY OF THE MAIN FUNCTION
}
Now, let us discuss the components of this code in detail:
● argc: It refers to “argument count”. It is the first parameter that we use
to store the number of command line arguments. It is important to note
that the value of argc should be greater than or equal to 0.
● agrv: It refers to “argument vector”. It is basically an array of character
pointers which we use to list all the command line arguments.

C Program to Understand the Command Line Arguments in C
Here is a code in C that illustrates the use of command line arguments.
// The program name is cl.c
#include<stdio.h>
int main(int argc, char** argv)
{
printf("Welcome to DataFlair tutorials!\n\n");
int i;
printf("The number of arguments are: %d\n",argc);
printf("The arguments are:");
for ( i = 0; i < argc; i++)
{
printf("%s\n", argv[i]);
}
return 0;
}
Pointers
★ Pointers in c
✔ Pointer is a special variable which holds the address of another
variable of same data type.
✔ A pointer is the memory address of an object. A pointer
variable is a variable that is specifically declared to hold a
pointer to an object of its specified type.

Address operator in c (reference operator ‘&’)
If you have a variable var in your program, &var will give you its address in the
memory, where & is commonly called the reference operator.
You must have seen this notation while using scanf() function. It was used in the
function to store the user inputted value in the address of var.
Program to demonstrate use of reference operator.:-
#include<stdio.h>
#include<conio.h>
void main()
{
int x=5;
clrscr();
printf("\n value of x:%d",x);
printf("\n address of x: %u",&x);
getch();
}
✔ Advantages of pointers:

1)call by address,thereby facilitating the changes made to a
variable in the called function to become permanently available in
the function from where the function is called.
2)return more than one value from a function indirectly.
3)pass arrays and strings more conveniently from one function to
another.
4)manipulate arrays more easily by moving pointers to them
instead of moving the arrays themselves.
✔ Declaration
datatype * pointer_variable;
ex: char *ptr;
The above example tells that ‘ptr’ is a identifier of pointer which can
store address of an character variable.
Note: All pointer variables take size of same amount.

Program to show, all pointer variables take same amount of size.
#include<stdio.h>
#include<conio.h>
void main()
{ int *p;
char *p1;
float *p2;
double *p3;
clrscr();
printf("\n size of the integer pointer is :%d",sizeof(p));
printf("\n size of char pointer is : %d",sizeof(p1));
printf("\n size of float pointer is: %d",sizeof(p2));
printf("\n size of double pointer is: %d",sizeof(p3));
getch();
}
✔ Initialisation of pointer
Let us assume that there is a variable ‘i’ we want to store its address
in an pointer ‘p’ the unary & operator is to be used. This is shown as
follows:
p=&i;
Program to show use of address operator with pointers.
#include<stdio.h>
#include<conio.h>
void main()
{
int i=5;
int *ptr=&i;
clrscr();
printf("\n address of i using &num is %p",&i);
printf("\n address of i using ptr is %p",ptr);
getch();
}
Note : Any number of pointers can point to the same address.

Note: Addresses must always be printed using %u or %p. If %p is used,
the address is printed in hexadecimal form. If %u is used, address is
printed in decimal form.
The primary use of a pointer is to access and, if appropriate change
the value of the variable that the pointer is pointing to. The other
pointer operator available in c is ‘*’, called the ‘value at address’
operator. It returns the value stored at a particular address. The value
at address operator is also called indirection operator or dereferencing
operator.
Program to show use of dereferencing operator with pointers.
#include<stdio.h>
#include<conio.h>
void main()
{
int x=5;
int *p=&x;
clrscr();
printf("\n value inside pointer p is %u",p);
printf("\n value of x using pointer is %d",*p);
getch();
}

Addition of two numbers using pointer variables.
#include<stdio.h>
#include<conio.h>
void main() {
int x,y,z;
int
*p,*p1,*p2;
p=&x;
p1=&y;
p2=&z;
clrscr();
printf("\n enter first number:");
scanf("%d",&x);
printf("\n enter second number:");
scanf("%d",&y);
*p2=*p+*p1;
printf("\n addition:%d",z);
getch();
}
Arrays and pointers
There is a close relation between arrays and pointers. Lets see
char str[30],*p;
p=str;
now if we want to access 7th element of array then it can be done in two ways
1) str[6]
(using array index)
2)
*(p+6)
(using pointers)
Note : Array name without an index returns address of the first
element in the array.
Program to demonstrate relation between arrays and pointers.
#include<stdio.h>

#include<conio.h>
void main()
{
int x[5]={10,20,30,40,50};
int *p;
p=x;
//array name without index returns address of first element of the
array
clrscr();
printf("\n 4th element : %d",x[3]);
printf("\n 4th element : %d",*(p+3));
getch();
}
Program to print array values using pointers.
#include<stdio.h>
#include<conio.h>
void main()
{
int x[5]={10,20,30,40,50};
int *p;
int i;
p=x;
clrscr();
for(i=0;i<5;i++)
printf("\n %d",*(p+i));
getch();
}
Strings and pointers
Strings are character array so like pointers are used on arrays similarly these can
be used on strings.
Program to demonstrate use of pointers with strings.
#include<stdio.h>
#include<conio.h>
void main()

{
char str[]="computer";
char *p;
int i;
clrscr();
p=str;
for(i=0;i<8;i++)
{
printf("\n %c",*p);
p++;
}
getch();
}
Program to demonstrate use of pointers with strings.
#include<stdio.h>
#include<conio.h>
void main()
{
char str[]="computer";
char *p;
clrscr();
p=str;
printf("\n *p=%c",*(++p));
printf("\n *p=%c",*p);
getch();
}
Functions and pointers:-
Program to swap two numbers using pointers and function.
#include<stdio.h>
#include<conio.h>
void swap(int *,int *);
void main()
{
int a=10,b=20;
clrscr();

printf("\n values before swap a=%d and b=%d",a,b);
swap(&a,&b);
printf("\n values after swap a=%d and b=%d",a,b);
getch();
}
void swap(int *p,int *q)
{
int temp;
temp=*p;
*p=*q;
*q=temp;
}
Call by value/reference
Function Arguments
If a function is to use arguments, it must declare variables that accept the values
of the arguments. These variables are called the formal parameters of the
function.
Formal parameters behave like other local variables inside the function and are
created upon entry into the function and destroyed upon exit.
While calling a function, there are two ways in which arguments can be passed
to a function −
Call by value: This method copies the actual value of an argument into the
formal parameter of the function. In this case, changes made to the parameter
inside the function have no effect on the argument.
Consider the function swap() definition as follows.
/* function definition to swap the values */
void swap(int x, int y) {
int temp;

temp = x; /* save the value of x */
x = y;
/* put y into x */
y = temp; /* put temp into y */
return;
}
Now, let us call the function swap() by passing actual values as in the following
example −
#include <stdio.h>
/* function declaration */
void swap(int x, int y);
int main () {
/* local variable definition */
int a = 100;
int b = 200;
printf("Before swap, value of a : %d\n", a );
printf("Before swap, value of b : %d\n", b );
/* calling a function to swap the values */
swap(a, b);
printf("After swap, value of a : %d\n", a );
printf("After swap, value of b : %d\n", b );
return 0;
}
void swap(int x, int y) {
int temp;
temp = x; /* save the value of x */
x = y;
/* put y into x */
y = temp; /* put temp into y */
return;
}
Let us put the above code in a single C file, compile and execute it, it will
produce the following result −

Before swap, value of a : 100
Before swap, value of b : 200
After swap, value of a : 100
After swap, value of b : 200
It shows that there are no changes in the values, though they had been changed
inside the function.
Call by reference: This method copies the address of an argument into the
formal parameter. Inside the function, the address is used to access the actual
argument used in the call. This means that changes made to the parameter affect
the argument.
So accordingly you need to declare the function parameters as pointer types as
in the following function swap(), which exchanges the values of the two integer
variables pointed to, by their arguments.
/* function definition to swap the values */
void swap(int *x, int *y) {
int temp;
temp = *x;
/* save the value at address x */
*x = *y;
/* put y into x */
*y = temp;
/* put temp into y */
return;
}
Let us now call the function swap() by passing values by reference as in the
following example #include <stdio.h>
int main () {
/* local variable definition */
int a = 100;
int b = 200;
printf("Before swap, value of a : %d\n", a );
printf("Before swap, value of b : %d\n", b );
/* calling a function to swap the values */
swap(&a, &b);

printf("After swap, value of a : %d\n", a );
printf("After swap, value of b : %d\n", b );
return 0;
}
void swap(int *x, int *y) {
int temp;
temp = *x; /* save the value of x */
*x = *y;
/* put y into x */
*y = temp; /* put temp into y */
Return;
}
Let us put the above code in a single C file, compile and execute it, to produce
the following result −
Before swap, value of a : 100
Before swap, value of b : 200
After swap, value of a : 200
After swap, value of b : 100
It shows that the change has reflected outside the function as well, unlike call by
value where the changes do not reflect outside the function.
Note: By default, C uses call by value to pass arguments. In general, it means
the code within a function cannot alter the arguments used to call the function
Iteration
Control statements
Many C statements rely upon a conditional expression that determines what course of
action is to be taken. A conditional expression evaluates to either a true or false value.
In C, true is any nonzero value, including negative numbers. A false value is 0. This
approach to true and false allows a wide range of routines to be coded extremely
efficiently.
★ Decisions Control Instructions

➢ C if else Statement
1) If statement
Syntax:
if(Expression)
{
// code to executed.
}
2) If-else statement
Syntax:
if(expression) {
//code to be executed if condition is true
}
else {
//code to be executed if condition is false
}

3) if-else if ladder
Syntax:
if(condition1) {
//code to be executed if condition 1 is true
}
else if(condition2) {
//code to be executed if condition 2 is true
}
else if(condition3) {
//code to be executed if condition 3 is true
}
else {
//code to be executed if all the conditions are false
}
Example Program:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf(“\n enter three numbers:”);
scanf(“%d %d %d”,&a,&b,&c);
if(a>b && a>c)
{
printf(“%d is greatest.”,a);
}
else if(b>c)
{

printf(“%d is greatest .”,b);
}
else
{
printf(“%d is greatest.”,c);
}
getch();
}
➢ Switch Case in C
C has a built-in multiple-branch selection statement, called switch, which
successively tests the value of an expression against a list of integer or
character constants. When a match is found, the statements associated with
that constant are executed.
Rules for switch case:
● Switch expression must be of integer or character type only.
● Case value must be integer or character constants.
● The break statement in switch case is not must. It is optional. If there is
no break statement found in switch case, all the cases will be executed
after matching the case value. It is known as fall through state of C
switch statement.
Syntax:
switch (expression)
{
case constant1: statement sequence
break;
case constant2: statement sequence
break;
case constant3: statement sequence
break;
default:
statement sequence
}

Example Program:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,ch;
printf(“\n enter two numbers:”);
scanf(“%d %d ”,&a,&b);
printf(“\n 1] ADD”);
printf(“\n 2]SUBTRACT”);
printf(“\n 3] MULTIPLY ”);
printf(“\n 4] DIVIDE”);
printf(“\n enter your choice:”);
scanf(“%d”,&ch);
switch(ch)
{
case 1: printf(“\n Add=%d”,a+b);
break;
case 2: printf(“\n Subtract=%d”,a-b);
break;
case 3: printf(“\n Multiplication=%d”,a*b);
break;
case 4: printf(“\n Divide=%d”,a/b);
break;
default: printf(“\n enter proper choice.”);
}
getch();
}
★ Loops in C
Let us take a scenario where we have to print same thing
10
times on
the console, using printf () function will make it complicated as we
have to write it 10 times. So here is the alternative, we will take the help
of looping.

In C, and all other modern programming languages, iteration statements (also
called loops) allow a set of instructions to be repeatedly executed until a certain
condition is reached.
There are three types of loops in C
1. for loop
2. while loop
3. do-while loop
1). for loop
➢ Syntax:
for(initialization; condition; increment/decrement)
{
//code to be executed;
}
Its used when we know how many times loop should run.

The for loop allows many variations, but its most common form works like this:
The initialization is an assignment statement that is used to set the loop control
variable. The condition is a relational expression that determines when the loop
exits. The increment defines how the loop control variable changes each time
the loop is repeated. You must separate these three major sections by
semicolons. The for loop continues to execute as long as the condition is true.
Once the condition becomes false, program execution resumes on the statement
following the for.
Program to print numbers from 1 to 100 using for loop.
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for(i=1;i<=100;i++)
{
printf(“\n %d”,i);
}
getch();
}
Execution:
The first thing here is that we have declared the loop variable(i). Second line
is having clrscr() function to clear the screen every time before execution.
Third line is having the for loop, here its declaration is done as
for(i=0(initialisation);i<100(condition);i++(i is incremented));
first, whatever written inside for loop will get printed for(i=0) then for(i=1)
and so on till i=99, as i become 100 condition gets false and control will
come out of the loop. So like this the statement inside for loop body will get
printed 100 times which is time saving as compared to writing printf() every
time.

Program to find factorial of a number.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,num,fact=1;
clrscr();
printf(“\n enter the
number :”);
scanf(“%d”,&num);
for(i=1;i<=num;i++)
{
fact=fact*i;
}
printf(“\n
factorial=%d”,fact);
getch();
}
Note: The Infinite Loop
for( ; ; ) printf("This loop will run forever.\n");
Program to check if given number is prime or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,num,flag=1;
clrscr();
printf(“\n enter any
number:”);
scanf(“%d”,&num);
for(i=2;i<num;i++)
{
if(num%i==0)
{

flag=2;
break;
}
}
if(flag==1)
printf(“number is
prime.”);
else
printf(“number is not
prime.”);
getch();
}
Execution:As every number is divisible by 1 so we have started our loop from
2 till number. We took ‘flag=1’, if the input number is divisible by any of the
numbers between (2 to (num-1)) then flag’s value will become 2, otherwise it
will remain 1 only.
After end of for loop, if flag is still 1 then number is prime otherwise number is
not prime.
➢ Nested for loop
When a loop occurs inside another loop is called nested for loop.
➢ Syntax:
for (initialise; condition; increment)
{
for (initialise; condition; increment)
{
statement(s);
}
statement(s);

}
PATTERN PROBLEMS
Program to print
* *
* * *
* * * *
* * * * *
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for (i=1 ; i<=5 ; i++)
{
for (j=1; j<=i ; j++)
{
printf (“*”);
}
printf(“\n”);
getch ();
}
}
Execution:
In these pattern problems, we have to keep in mind that
number of columns are controlled by outer loop (i loop) and number of rows by
inner loop (j loop). Now in this case we need a half pyramid so for that we will
control the inner loop from outer loop that’s why terminating condition for ‘j’
loop is having ‘i’ in it.

Step 1:
i=1 and j=1(j is less than equal to 1), prints ‘*’
i=1 and j=2(j is not less than equal to 1), inner loop breaks, newline
Step 2:
i=2 and j=1(j is less than equal to 2), prints ‘*’
i=2 and j=2(j is less than equal to 2), prints ‘*’
i=2 and j=3(j is not less than equal to 2), inner loop breaks, newline
* *
Step 3:
i=3 and j=1(j is less than equal to 3), prints ‘*’
i=3 and j=2(j is less than equal to 3), prints ‘*’
i=3 and j=3(j is less than equal to 3), prints ‘*’
i=3 and j=4(j is not less than equal to 3), inner loop breaks, newline
* *
* * *
Step 4:
i=4 and j=1(j is less than equal to 4),prints ‘*’
i=4 and j=2(j is less than equal to 4),prints ‘*’
i=4 and j=3(j is less than equal to 4),prints ‘*’
i=4 and j=4(j is less than equal to 4),prints ‘*’
i=4 and j=5(j is not less than equal to 4), inner loop breaks, newline
* *
* * *

* * * *
Step 5:
i=5 and j=1(j is less than equal to 5), prints ‘*’
i=5 and j=2(j is less than equal to 5), prints ‘*’
i=5 and j=3(j is less than equal to 5), prints ‘*’
i=5 and j=4(j is less than equal to 5), prints ‘*’
i=5 and j=5(j is less than equal to 5), prints ‘*’
i=5 and j=6(j is not less than equal to 5), inner and outer loop breaks.
* *
* * *
* * * *
* * * * *
Program to print:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1 ; i<=5 ; i++)
{
for(j=1 ; j<=i ; j++)
{

printf(“%d”,i);
}
printf(“\n”);
getch();
}
}
Execution:
Here we observe that in a particular row the value to be printed remains
constant so if we print ‘i’ then the desired output can be achieved.
2) While loop
✔ It’s a pre-test loop, it evaluates the test expression before every iteration
of the loop.
✔ It is used when it is not known in advance that when loop should
terminate.
✔ Syntax:
while(condition)
{
//code to be executed
}

Program to print numbers from 1 to 5 using while loop.
#include<stdio.h>
#include<conio.h>
void main ()
{
int x=1;
clrscr();
while(x<=5)
{
printf(“\n %d”,x);
x++;
}
getch();
}
Program to find sum of the digits of a given number:
#include<stdio.h>
#include<conio.h>
void main ()
{

int num, rem, sum=0;
clrscr();
printf(“\n enter any
number:”);
scanf(“%d”,&num);
while(num>0)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
printf(“\n sum of digits :
%d”,sum);
getch();
}
3)Do-While loop
✔ This loop also does the same work what ‘for’ and ‘while’ loop do,but
the only difference here is that it checks the condition at the end of the
loop(so loop will at least run once).
✔ Its exit controlled loop.
✔ Syntax:
do
{
//code to be executed
} while(condition);

Program to restrict user to enter a positive age.
#include<stdio.h>
#include<conio.h>
void main ()
{
int age;
clrscr();
do
{
printf(“\n enter age:”);
scanf(“%d”,&age);
} while(age<0);
printf(“\n your age=%d”,age);
getch();
}
Now sometimes while using loop’s there may come conditions where we want
loop to get terminated or skip that particular iteration, for these operations we
are being provided by two keywords break and continue.

➢ break statement in C
✔ Break statement in c is used to break execution of loop and switch
case.
✔ In case of nested loops, if break used inside the inner loop it will
break inner loop only not the outer one.
✔ break keyword can be used for only loops and switch case.
Program to break loop when value of loop variable becomes 5:
#include<stdio.h>
#include<conio.h>
void main ()
{
int i;
for(i=0;i<10;i++)
if(i==5)
break;
getch();
}

➢ continue statement in C
✔ The continue statement in C programming works somewhat like
the break statement. Instead of forcing termination, it forces the
next iteration of the loop to take place, skipping any code in
between.
5.Program to continue loop when value of loop variable becomes
#include<stdio.h>
#include<conio.h>
void main ()
{
int i;
for(i=0;i<10;i++)
if(i==5)
continue;
getch();}

Recursion
★ Recursion in c
A recursive function is one that calls itself directly or indirectly to solve a
smaller version of its task until a final call which does not require a self-call.
All recursion problems can also be solved with loops but not all loop problems
can be solved by recursion.
Program to calculate factorial using recursion:-
#include<stdio.h>
#include<conio.h>
int factorial(int num)
{
if(num==1)
return 1;
else
return (num*factorial(num-1));
}
void main()
{
int num,fact;
clrscr();
printf("\n enter any number:");
scanf("%d",&num);
fact=factorial(num);
printf("\n factorial of the number is: %d",fact);
getch();
}
Program to find sum of natural numbers using recursion :-
#include<stdio.h>
#include<conio.h>

int sum(int num)
{
if(num==0)
return 0;
else
return (num+sum(num-1));
}
void main()
{
int num,s;
clrscr();
printf("\n enter number of terms:");
scanf("%d",&num);
s=sum(num);
printf("\n sum of first %d natural numbers is:%d",num,s);
getch();
}
Program to find HCF of two numbers using recursion.
#include <stdio.h>
int hcf(int, int);
void main()
{
int a, b, result;
clrscr();
printf("Enter the two numbers to find their HCF: ");
scanf("%d%d", &a, &b);
result = hcf(a, b);
printf("The HCF of %d and %d is %d.\n", a, b, result);
getch();
}
int hcf(int a, int b)
{
while (a != b)
{
if (a > b)
{

return hcf(a - b, b);
}
else
{
return hcf(a, b - a);
}
}
return a;
}
Program to reverse a number using recursion.
#include<stdio.h>
void main()
{
int num,reverse_number;
clrscr();
printf("\nEnter any number:");
scanf("%d",&num);
reverse_number=reverse_function(num);
printf("\nAfter reverse the no is :%d",reverse_number);
getch();
}
int sum=0,rem;
reverse_function(int num)
{
if(num)
{
rem=num%10;
sum=sum*10+rem;
reverse_function(num/10);
}
else
return sum;
return sum;
}