0% found this document useful (0 votes)
10 views

Basics

C is a widely used programming language. It is commonly used to develop operating systems, system applications, desktop applications, and embedded systems. Some key features of C include using header files like stdio.h, having a main() function as the program entry point, and using functions like printf() for output and scanf() for input. C is a compiled language that uses tools like compilers to convert source code into machine-readable object files and executable programs. Popular C compilers include Clang, MinGW, and Turbo C.

Uploaded by

rohitggothi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Basics

C is a widely used programming language. It is commonly used to develop operating systems, system applications, desktop applications, and embedded systems. Some key features of C include using header files like stdio.h, having a main() function as the program entry point, and using functions like printf() for output and scanf() for input. C is a compiled language that uses tools like compilers to convert source code into machine-readable object files and executable programs. Popular C compilers include Clang, MinGW, and Turbo C.

Uploaded by

rohitggothi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Basics

C prog
C Basic Commands

This command includes standard input


#include <stdio.h> output header file(stdio.h) from the C
library before compiling a C program
It is the main function from where C
int main() program execution begins.
Indicates the beginning of the main
{ function.
Whatever written inside this command
“/* */” inside a C program, it will not be
/*_some_comments_*/ considered for compilation and
execution.
This command prints the output on the
printf(“Hello_World! “); screen.
This command is used for any character
getch(); input from keyboard.
This command is used to terminate a C
return 0; program (main function) and it returns
0.
It is used to indicate the end of the
}
Where is C used? Key Applications
1.ʻCʼ language is widely used in embedded systems.
2.It is used for developing system applications.
3.It is widely used for developing desktop applications.
4.Most of the applications by Adobe are developed using ʻCʼ programming language.
5.It is used for developing browsers and their extensions. Googleʼs Chromium is built using ʻCʼ programming
language.
6.It is used to develop databases. MySQL is the most popular database software which is built using ʻCʼ.
7.It is used in developing an operating system. Operating systems such as Appleʼs OS X, Microsoftʼs
Windows, and Symbian are developed using ʻCʼ language. It is used for developing desktop as well as
mobile phoneʼs operating system.
8.It is used for compiler production.
9.It is widely used in IOT applications.
How C Programming Language Works?

C is a compiled language. A compiler is a special tool that compiles the program and converts it
into the object file which is machine readable.
After the compilation process, the linker will combine different object files and creates a single
executable file to run the program.
The following diagram shows the execution of a ʻCʼ program
Following is the list of popular compilers available online:

•Clang compiler
•MinGW compiler (Minimalist GNU for Windows)
•Portable ʻCʼ compiler
•Turbo C
First C Program

#include <stdio.h> includes the standard input output library


#include <stdio.h> functions. The printf() function is defined in stdio.h .
int main()
{
printf("Hello C Language"); int main() The main() function is the entry point of every
program in c language.
return 0;
}
printf(): - The printf() function is used to print data on the
console.
return 0 The return 0 statement, returns execution status to the
OS. The 0 value is used for successful execution and 1 for
unsuccessful execution
printf() and scanf() in C The printf() and scanf() functions are used for input and output in C language.
Both functions are inbuilt library functions, defined in stdio.h (header file).

printf() function
The printf() function is used for output. It prints the given statement to the
console

printf(“Msg”);
printf("format string",argument_list);
The format string can be %d (integer), %c (character), %s (string), %f (float) etc
scanf() function The scanf() function is used for input. It reads the input data
from the console

scanf("format string",argument_list);

#include<stdio.h>
int main()
{
int number;
printf("enter a number:");
scanf("%d",&number);
printf("cube of number is:%d ",number*number*number);
return 0;
}
Variables Variables are containers for storing data values.

In C, there are different types of variables for example:


int - stores integers (whole numbers), without decimals,
such as 123 or -123.
float - stores floating point numbers, with decimals, such as
19.99 or -19.99.
A variable must be declared first before it is used somewhere
inside the program.

A variable name is formed using characters,


digits and an underscore.
Following are the rules that must be followed while creating a
variable:
1.A variable name should consist of only characters, digits and an underscore.

2.A variable name should not begin with a number.

3.A variable name should not consist of whitespace.

4.A variable name should not consist of a keyword.

5.ʻCʼ is a case sensitive language that means a variable named ʻageʼ and ʻAGEʼ are
different.
Following are the examples of valid variable names in a ʻCʼ program:

height or HEIGHT
_height
_height1
My_name

Following are the examples of invalid variable names in a ʻCʼ program:

1height
Hei$ght
My name
Data Types in C

Each variable in C has an associated data type.

Each data type requires different amounts of memory and


has some specific operations which can be performed over
it.

It specifies the type of data that the variable can store like
integer, character, floating, double, etc.
Basic Data Types the most basic ones:

int 2 or 4 bytes Stores whole numbers, without decimals

float 4 bytes Stores fractional numbers, containing one or


more decimals. Sufficient for storing 7 decimal
digits

double 8 bytes Stores fractional numbers, containing one or


more decimals. Sufficient for storing 15 decimal
digits

char 1 byte Stores a single character/letter/number, or


ASCII values
Basic Format Specifiers

Format Specifier Data Type


%d or %i int
%f float
%lf double
%c char
%s Used for strings (text
#include <stdio.h>

int main()
{
double dNum = 99.99; // Double (floating point number)

printf("%lf", dNum);
return 0;
}
Format Minimal
Size Of Data Types In C Data Type Size in bit
Specifier Range

char %c -127 to 127 8

-32,767 to
int %d, %i 16 or 32
32,767
-2,147,483,64
7 to
long int %ld, %li 32
2,147,483,64
7
1E-37 to
1E+37 along
float %f with six digits 32
of the
precisions
1E-37 to
1E+37 along
double %lf with six digits 80
of the

You might also like