0% found this document useful (0 votes)
8 views31 pages

Short Course On C Programming

The document outlines a short course on C programming offered by B.L.D.E.A's V.P. Dr. P.G. Halakatti College of Engineering and Technology, covering fundamental concepts such as program structure, data types, variables, operators, decision making, looping, arrays, strings, structures, unions, and pointers. It emphasizes the advantages of C programming and provides an overview of key programming constructs and their usage. The course aims to equip learners with essential skills in C programming for various applications.

Uploaded by

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

Short Course On C Programming

The document outlines a short course on C programming offered by B.L.D.E.A's V.P. Dr. P.G. Halakatti College of Engineering and Technology, covering fundamental concepts such as program structure, data types, variables, operators, decision making, looping, arrays, strings, structures, unions, and pointers. It emphasizes the advantages of C programming and provides an overview of key programming constructs and their usage. The course aims to equip learners with essential skills in C programming for various applications.

Uploaded by

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

B.L.D.E.A’S V. P. DR. P. G.

HALAKATTI COLLEGE OF
ENGINEERING AND TECHNOLOGY,
VIJAYPUR 586 103

Department
of CSE(AI &
ML) SHORT COURSE ON C
PROGRAMMING

Poornima M
AGENDA
 Introduction
 Program structure
 Data types
 Variable & Keywords
 Constants & literals
 Operators
 Decision making
 Looping & iteration
 Arrays, string, structure & Union
 Pointers
INTRODUCTION
 C programming is a general-purpose, procedural,
imperative computer programming language developed in
1972 by Dennis M. Ritchie at the Bell Telephone
Laboratories to develop the UNIX operating system.

 Advantages of C programming language


i. Easy to learn
ii. Structured language
iii. It produces efficient programs
iv. It can handle low-level activities
v. It can be compiled on a variety of computer platforms
PROGRAM STRUCTURE

 A C program basically consists of the following


parts −
i. Preprocessor Commands
ii. Functions
iii. Variables
iv. Statements & Expressions
v. Comments

 Hello World Example


DATA TYPES

 In C Programming Language every variable must have attached


a data type to it, data type for a variable defines:
i. The amount of memory space allocated for variables.
ii. A data type specifies the possible values for variables.
iii. The operations that can be performed on variables.

 In C Programming Language data types can be broadly


classified as:
i. Primary data types - nit. float, double, char, void.
ii. Derived data types - Derived from primitive data type ex:
array, pointer, function etc.
iii. User-defined data types- Defined by the programmer himself.
VARIABLE & KEYWORDS

 A variable is nothing but a name given to a storage area


that our programs can manipulate. Each variable in C has
a specific type, which determines the size and layout of
the variable's memory; the range of values that can be
stored within that memory; and the set of operations that
can be applied to the variable.
KEYWORDS
 In C Programming Language there are set words that you
cannot use as an identifier. These words are known as
‘reserved” words or “Keywords”. Keywords are standard
identifiers and their meaning and purpose is predefined by
the compiler.
CONSTANTS & LITERALS

 Constants refer to fixed values that the program may not


alter during its execution. These fixed values are also
called literals.
 Constants can be of any of the basic data types like an
integer constant, a floating constant, a character constant,
or a string literal. There are enumeration constants as
well.
 Constants are treated just like regular variables except
that their values cannot be modified after their definition.

 Defining Constants
There are two simple ways in C to define constants −
1. Using #define preprocessor.
2. Using const keyword.
OPERATORS

 An operator is a symbol that tells the compiler to perform


specific mathematical or logical functions. C language is
rich in built-in operators and provides the following types
of operators −

1. Arithmetic Operators
2. Relational Operators
3. Logical Operators
4. Bitwise Operators
5. Assignment Operators
6. Misc Operators
ARITHMETIC OPERATORS
RELATIONAL OPERATORS
LOGICAL OPERATORS
BITWISE OPERATORS
ASSIGNMENT OPERATORS
MISC OPERATORS
C DECISION MAKING

 Decision making structures require that the programmer


specifies one or more conditions to be evaluated or tested
by the program, along with a statement or statements to
be executed if the condition is determined to be true, and
optionally, other statements to be executed if the
condition is determined to be false.
 General form of a typical decision making structure found
in most of the programming languages −
 C programming language provides the following
types of decision making statements.
C LOOPING & ITERATION

 In general, statements are executed sequentially: The first


statement in a function is executed first, followed by the
second, and so on. Programming languages provide various
control structures that allow for more complicated execution
paths.
 A loop statement allows us to execute a statement or group
of statements multiple times. Given below is the general
form of a loop statement in most of the programming
languages
C programming language provides the following types of loops
to handle looping requirements.
 Loop Control Statements
 Loop control statements change execution from its normal
sequence. When execution leaves a scope, all automatic
objects that were created in that scope are destroyed.
 C supports the following control statements.
 Arrays a kind of data structure that can store a fixed-size
ARRAYS, STRING, STRUCTURE & UNION

sequential collection of elements of the same type. An


array is used to store a collection of data, but it is often
more useful to think of an array as a collection of variables
of the same type.
 All arrays consist of contiguous memory locations. The
lowest address corresponds to the first element and the
highest address to the last element.

 Declaring Arrays
To declare an array in C, a programmer specifies the type
of the elements and the number of elements required by
an array as follows −
type arrayName [ arraySize ];
TYPES OF ARRAYS
 Single dimensional Arrays

 Multi-dimensional Arrays
STRINGS
 Strings are actually one-dimensional array of characters
terminated by a null character '\0'. Thus a null-terminated
string contains the characters that comprise the string
followed by a null.
 The following declaration and initialization create a string
consisting of the word "Hello". To hold the null character at
the end of the array, the size of the character array
containing the string is one more than the number of
characters in the word "Hello."
 char greeting[6] = {'H', 'e', 'l', 'l', 'o', '\0'}; If you follow the
rule of array initialization then you can write the above
statement as follows −
 char greeting[] = "Hello";
 C supports a wide range of functions that manipulate null-
terminated strings −
STRUCTURE
 Arrays allow to define type of variables that can hold
several data items of the same kind.
Similarly structure is another user defined data type
available in C that allows to combine data items of
different kinds.
 To define a structure, you must use the struct statement.
The struct statement defines a new data type, with more
than one member. The format of the struct statement is as
follows-
 The structure tag is optional and each member definition
is a normal variable definition, such as int i; or float f; or
any other valid variable definition. At the end of the
structure's definition, before the final semicolon, you can
specify one or more structure variables but it Is optional.

 To access any member of a structure, we use the member


access operator (.). The member access operator is
coded as a period between the structure variable name
and the structure member that we wish to access.
UNION
 A union is a special data type available in C that allows to
store different data types in the same memory location.
Unions provide an efficient way of using the same
memory location for multiple-purpose.

 The union tag is optional and each member definition is a


normal variable definition, such as int i; or float f; or any
other valid variable definition. At the end of the union's
definition, before the final semicolon, you can specify one
or more union variables but it is optional.
C POINTERS

 Pointers in C are easy and fun to learn. Some C


programming tasks are performed more easily with
pointers, and other tasks, such as dynamic memory
allocation, cannot be performed without using pointers. So
it becomes necessary to learn pointers to become a
perfect C programmer
 A pointer is a variable whose value is the address of
another variable, i.e., direct address of the memory
location.
 The general form of a pointer variable declaration is −
type *var-name;
 Here, type is the pointer's base type; it must be a valid C
data type and var-name is the name of the pointer
variable. The asterisk * used to declare a pointer is the
same asterisk used for multiplication.
FEW OPERATIONS TO BE FOLLOWED
WHILE USING POINTERS
(a) We define a pointer variable
(b) assign the address of a variable to a pointer and
(c) finally access the value at the address available in the
pointer variable.
THE FOLLOWING EXAMPLE
MAKES USE OF POINTER −
THANK YOU

You might also like