Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
16 views

C - Programming Lect 1,2,3,4

The document provides an introduction to the C programming language. It discusses what programming and coding are, important advantages of learning C, and gives an overview of key aspects of C including its character set, keywords, variables, data types, and basic syntax structures. The document is intended to provide foundational knowledge about C to beginners learning the language.

Uploaded by

groverpranjal34
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

C - Programming Lect 1,2,3,4

The document provides an introduction to the C programming language. It discusses what programming and coding are, important advantages of learning C, and gives an overview of key aspects of C including its character set, keywords, variables, data types, and basic syntax structures. The document is intended to provide foundational knowledge about C to beginners learning the language.

Uploaded by

groverpranjal34
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Introduction to C

Programming

C Programming

Dr. Gaganpreet Kaur


Associate Professor

16/02/2024 IWT-WEB PROGRAMMING-FEE 1


Programming ?

● Programming is a collaboration between humans and computers.

PROGRAMMING IS EVERYWHERE - order, movies .

● Tech companies are no longer recognizable as just software companies —


instead, they bring food to our door, help us get a taxi, influence outcomes in
presidential elections, or act as a personal trainer .
Programming ?

● …AND PROGRAMMING IS FOR EVERYONE -


● few people have known how to code before now .
● Now 31.1 million software developers worldwide .
So what is Coding ?

Ok, so now I know what programming is, but what’s coding?


● interchangeably, programming and coding actually have different
definitions.
● Programming is the mental process of thinking up instructions to give to a
machine (like a computer).
● Coding is the process of transforming those ideas into a written language that
a computer can understand.
Important Advantages of learning C programming -

● C is a Middle - Level Language.


● Helps to understand the fundamentals of Computer Theories.
● Fewer Libraries.
● C is very fast in terms of execution time.
● Embedded Programming. (microcontrollers)
● It is widely used in auto-motives, Robotics, Hardware etc.
● For Company Placements.
Introduction to C Programming

● C is a general purpose language.


● It is very closely associated with UNIX.
● It was developed in Bell Laboratories.
● Dennies Ritchie wrote C in 1972.
● C was intended to be useful for busy
programmers .
ABOUT “C”

● C is a structured programming language.


● C supports functions that enables easy maintainability of
code, by breaking large file into smaller modules .
● Comments in C provides easy readability.
● C is a powerful language.
ABOUT “C”

C programs built from


● Variable and type declarations
● Functions
● Statements
● Expressions
Structure of “C” Programs

● Before going and reading the structure of C programs we need to have basic
knowledge of the following :
1. C’s Character Set
2. C’s Keywords
3. The General Structure of a ‘C’ Program
4. How to End a Statement
5. Free Format Languages
6. Header file & Library Functions
C’s Character Set

C does not use every character set .


The only characters that C - language uses for its
programs are as follows:
● A-Z , a-z all alphabets
● 0-9
● # % & ! _ {} [] () $ & |
● space . , : ; ‘ ”
● +-/*=
The Keywords

● “Keywords” are words that have that have special meanings to the compiler.
a compiler is a computer program that translates computer code written in one programming language (the source
language) into another language (the target language). The name "compiler" is primarily used for programs that
translate source code from a high-level programming language .
Keywords in C

As C is a case sensitive language, all keywords must be written in lowercase. Here is a list of all
keywords allowed in ANSI C.
Example of keyword-

Int - Keyword
Money - Variable of type int (integer)
C Identifiers

● Identifiers refers to name given to entities such as


variables ,functions,structures etc.
● Identifiers must be unique.
● They are created to give a unique name to an entity to identify it during
the execution of the program.

● Here, money and accountBalance are identifiers.


● Exmoles total, sum, average, _m _, sum_1, etc.
Rules for naming Identifiers

● A valid identifier can have letters (both uppercase and lowercase

letters), digits and underscores.


● The first letter of an identifier should be either a letter or an underscore.
● You cannot use keywords like int, while etc. as identifiers.
● There is no rule on how long an identifier can be. However, you may

run into problems in some compilers if the identifier is longer than 31


characters.
C Variables

● In programming, a variable is a container (storage area) to hold data.

● To indicate the storage area, each variable should be given a unique name (identifier).
● Variable names are just the symbolic representation of a memory location.

● Here, playerScore is a variable of int type. Here, the variable is assigned an integer value 95.
● The value of a variable can be changed, hence the name variable.
Rules for naming a Variable

● A variable name can only have letters (both uppercase and lowercase letters),
digits and underscore.
● The first letter of a variable should be either a letter or an underscore.
● There is no rule on how long a variable name (identifier) can be. However, you
may run into problems in some compilers if the variable name is longer than 31
characters.
Note : You should always try to give meaningful names to variables. For
example: firstName is a better variable name than fn.
Rules for naming a Variable

C is a strongly typed language. This means that the variable type cannot be changed
once it is declared. For example:

Here, the type of number variable is int. You cannot assign a floating-point (decimal)
value 5.5 to this variable. Also, you cannot redefine the data type of the variable to double.
By the way, to store the decimal values in C, you need to declare its type to either double
or float.
C Data types
Int

Integers are whole numbers that can have both zero, positive and
negative values but no decimal values. For example, 0, -5, 10.

Here, id is a variable of type integer.


You can declare multiple variables at once in C programming. For example,
Float and double

● float and double are used to hold real numbers.

In C, floating-point numbers can also be represented in exponential. For example,


Char

Keyword char is used for declaring character type variables. For example,

The size of the character variable is 1 byte.

void is an incomplete type. It means "nothing" or "no type". You can think of void as absent.

For example, if a function is not returning anything, its return type should be void.

Note that, you cannot create variables of void type.


Short and Long

If you need to use a large number, you can use a type specifier long. Here's how:

Here variables a and b can store integer values. And, c can store a floating-point number.
If you are sure, only a small integer ([−32,767, +32,767] range) will be used, you can use short.
Short and Long

You can always check the size of a variable using the sizeof() operator.
Singed and Unsigned

In C, signed and unsigned are type modifiers. You can alter the data storage of a data type by using
them:

● signed - allows for storage of both positive and negative numbers


● unsigned - allows for storage of only positive numbers

You might also like