PresentationPDF Available

Abstract and Figures

In this presentation, the authors try to cover the basics of C programming skills.
Content may be subject to copyright.
Basics of C Programming
Dr. Nilu Singh
School of Computer Applications
Babu Banarasi Das University
Lucknow-UP
Introduction of C
Structure of a C-language program
Write your first C program
Preprocessor command
Identifiers for objects in a program
C basic data types
Variables and constants
Input and output concepts
C is a structured programming
language.
It is considered a high-level language
because it allows the programmer to
concentrate on the problem at hand and
not worry about the machine that the
program will be using.
C is a case-sensitive language.
C evolved from two previous languages, BCPL
(Basic Combined Programming Language) and
B.
BCPL developed in 1967 by Martin Richards
as a language for writing O.S and compilers.
Ken Thompson modeled many features in his
language, B, after their counterparts in BCPL,
and used B to create an early versions of
UNIX operating system at bell Laboratories in
1970 on a DEC PDP-7 computer.
2/4
Both BCPL and B were type-less languages:
the only data type is machine word and
access to other kinds of objects is by special
operators or function calls.
The C language developed from B by Dennis
Ritchie at Bell Laboratories and was originally
implemented on a DEC PDP-11 computer in
1972.
It was named C for new language (after B).
Initially, C used widely as the development
language of the UNIX OS.
2/4
In 1983, the X3J11 technical committee was
created under the American National Standards
Institute (ANSI) Committee on Computer and
Information Processing (X3) to provide an
unambiguous and machine-independent
definition of the language and approved in 1989,
called ANSI C.
Then, the document is referred to as ANSI/ISO
9899:1990.
The second edition of Kernighan and Ritchie,
published in 1988, this version called ANSI C,
then used worldwide.
Today, almost all new major OS are written in
C including Windows.
Structure of a C-language program
Fig. 1 Structure of a C Program
C Programming Basics to Write A C Program
C Basic commands
Explanation
#include <
stdio.h>
This is a preprocessor command that includes
standard input output header file(
stdio.h) from
the C library before compiling a C program
int
main()
This is the main function from where execution
of any C program begins.
{
This indicates the beginning of the main
function.
/*_
some_comments_*/
whatever is given inside the command “/*
*/”
in any C program, won’t be considered for
compilation and execution.
printf
(“Hello_World! “);
printf
command prints the output onto the
screen.
getch
();
This command waits for any character input
from keyboard.
return 0;
This command terminates C program
(main function) and returns 0.
}
This indicates the end of the main
function.
#include <stdio.h>
int main()
{
/* Our first simple C basic
program */
printf("Hello World! ");
getch();
return 0;
}
Steps to Write C Programs and Get the
Output
This is common to all C program
Create
Compile
Execute or Run
Get the Output
Key Points
Each C programming statement is ended
with semicolon (;) which are referred as
statement terminator.
A header file is a file with extension .h
which contains C function declarations and
macro definitions to be shared between
several source files.
Printf() command is used to print the output
onto the screen.
C programs are compiled using C compilers
and displays output when executed.
Identifiers
One feature present in all computer languages
is the identifier.
Identifiers allow us to name data and other
objects in the program.
Each identified object in the computer is stored
at a unique address.
An identifier must start with a letter or
underscore: it may not have a space or a
hyphen.
Rules for Identifiers
Example
Correct Incorrect
testprogram
1sttestprogram /* starts with a digit */
_
arrayex
%
arrayex /* contains invalid character */
charAndNum
char
/* reserved word */
structure_pr
g
Structure
prg /* contains a space */
Variables
Variables are named memory locations that
have a type, such as integer or character, which
is inherited from their type.
The type determines the values that a variable
may contain and the operations that may be
used with its values.
When a variable is defined, it is not initialized.
We must initialize any variable requiring
prescribed data when the function starts.
Variable Declaration/Initialisation
Constants
Constants are data values that cannot be
changed during the execution of a program. Ex.
variables, constants have a type.
A character constant is enclosed in single
quotes.
Symbolic Names for Control Characters
Conti
Use single quotes for character constants.
Use double quotes for string constants.
C OPERATORS
An expression is any valid set of literals,
variables, operators, operands and
expressions that evaluates to a single value.
This value can be a number, a string or a
logical value.
For instance a = b + c; denotes an
expression in which there are 3 operands a,
b, c and two operator + and =.
A statement, the smallest independent
computational unit, specifies an action to be
performed.
Conti…
In most cases, statements are executed in
sequence.
The number of operands of an operator is
called its arity.
Based on arity, operators are classified as
nullary (no operands), unary (1 operand),
binary (2 operands), ternary (3 operands).
C Keywords/Reserved Words
auto
break
case
char
const
continue
default
do
double
else
enum
extern
float
for
goto
if
inline (C99 beyond)
int
long
register
restrict (C99
beyond)
return
short
signed
sizeof
static
struct
switch
typedef
union
unsigned
void
volatile
while
_Alignas (C11)
_Alignof (C11)
_Atomic (C11)
_Bool (C99 beyond)
_Complex (C99 beyond)
_Generic (C11)
_Imaginary (C99 beyond)
_Noreturn (C11)
_Static_assert (C11)
_Thread_local (C11)
Comments
Single line of comment: // comment here
More than single line of comment or
expanded: /* comment(s) here */
printf()
function, where program
execution starts */
/* declares variable and initializes it*/
int i = 8;
Characteristics of C
C is a general-purpose programming
language that is extremely popular, simple
and flexible.
It is machine-independent, structured
programming language which is used
extensively in various applications.
C was the basics language to write
everything from operating systems
(Windows and many others) to complex
programs like the Oracle database, Git,
Python interpreter and more.
Applications of C
'C' language is widely used in embedded
systems.
It is used for developing system
applications.
It is widely used for developing desktop
applications.
Most of the applications by Adobe are
developed using 'C' programming language.
It is used for developing browsers and their
extensions. Google's Chromium is built
using 'C' programming language.
Conti…
It is used to develop databases. MySQL is
the most popular database software which
is built using 'C'.
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.
It is used for compiler production.
It is widely used in IOT applications.
Thank You
References
https://fresh2refresh.com/c-programming/c-
basic-program/
https://www.programiz.com/c-programming
https://www.guru99.com/c-programming-
language.html
ResearchGate has not been able to resolve any citations for this publication.
ResearchGate has not been able to resolve any references for this publication.