Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Other

C language BEGINNER to PRO level notes

Rating
-
Sold
-
Pages
26
Uploaded on
03-03-2023
Written in
2022/2023

EASY EXPLAINATION OF THE TOPICS, SO THAT THE BEGINNER SHOULD EASILY UNDERSTAND IT AND LEARN TO MAKE PROGRAMMS.

Institution
Course

Content preview

C PROGRAMMING NOTES

C programming language- C is a high-level, general-purpose programming language that was
originally designed and developed by Dennis Ritchie at Bell Labs in the 1970s. It is one of the
most popular and widely used programming languages today, known for its speed, efficiency,
and flexibility.

C is a compiled language, which means that the source code must be converted into machine
code before it can be executed on a computer. It is used for a wide range of applications,
including operating systems, embedded systems, software development, game programming,
and scientific research.

C provides a rich set of programming constructs, including variables, data types, control
structures, functions, and pointers. It is a relatively low-level language, providing direct access to
memory and hardware resources, which makes it highly efficient and adaptable for systems
programming.

C has influenced many other programming languages, including C++, Java, Python, and many
others. It continues to be an important language for software development, and many
developers and programmers consider it an essential tool in their arsenal.



Variables- Variable is the name of a memory location which stores some data.
In the C programming language, a variable is a named storage location that can hold a value. Variables
are used to store data that is used in a program, and their value can be changed during the execution of
the program.

To declare a variable in C, you specify its data type, followed by its name. For example, to declare an
integer variable named "myVariable", you would use the following code:

int myVariable;

This declares a variable named "myVariable" of type integer. You can also assign an initial value to the
variable at the time of declaration by using the assignment operator (=). For example:

int myVariable = 42;

This declares a variable named "myVariable" of type integer and assigns it an initial value of 42.

To assign a new value to a variable, you simply use the assignment operator (=) followed by the new
value. For example:

myVariable = 23;

,This assigns a new value of 23 to the variable "myVariable".

In C, variables have a scope that determines where they can be accessed. A variable declared inside a
function, for example, can only be accessed within that function. A variable declared outside of any
function, on the other hand, can be accessed by any function in the program.

It's important to initialize variables before using them to avoid accessing an undefined value, which can
cause unexpected behavior or errors in the program.

There are several types of variables:

• Integer variables: These variables hold whole number values (positive, negative, or zero) and are
declared using the keyword "int".
• Floating-point variables: These variables hold decimal or fractional values and are declared using
the keywords "float" or "double".
• Character variables: These variables hold single character values (e.g., 'a', 'b', 'c') and are
declared using the keyword "char".
• Boolean variables: These variables hold either true or false values and are declared using the
keyword "bool" (which is a part of the C99 standard).
• Pointer variables: These variables hold memory addresses and are declared using the "*" symbol
(e.g., "int *ptr").
• Array variables: These variables hold a collection of values of the same data type and are
declared using brackets (e.g., "int myArray[10]").
• Structure variables: These variables hold a collection of related variables of different data types
and are declared using the "struct" keyword (e.g., "struct person { char name[20]; int age; }
myPerson;").



In the C programming language, there are several rules that must be followed when declaring and using
variables:

• Variable names must start with a letter or underscore character.
• Variable names cannot be the same as a keyword or reserved word in C.
• Variable names can only contain letters, numbers, and underscores.
• Variable names are case sensitive (i.e., "myVariable" and "myvariable" are two different
variables).
• Variable names should be descriptive and meaningful.
• Variables must be declared before they are used in the program.
• Each variable must have a unique name within the same scope.
• The data type of a variable cannot be changed after it has been declared.
• Variables should be initialized with a value before they are used to avoid accessing an undefined
value.
• Variables can only hold values of their declared data type.

, In C programming language, there are several data types that can be used to define variables. These data
types are:

• int: Used for integer values, such as 1, 2, -3, etc.
• char: Used for a single character value, such as 'a', 'b', 'c', etc.
• float: Used for floating-point values with a single precision, such as 3.14, 1.23, etc.
• double: Used for floating-point values with double precision, such as 3.1415926535,
1.23456789, etc.
• void: Used to indicate that the variable has no data type. This is typically used for function
pointers.
• short: Used for integers with a smaller range than "int".
• long: Used for integers with a larger range than "int".
• unsigned: Used for integers that can only have positive values.
• signed: Used for integers that can have both positive and negative values (this is the default for
"int" in C).
• _Bool: Used for Boolean values, which can only be "true" or "false".
• _Complex: Used for complex numbers, which have a real and imaginary part.
• enum: Used to define a set of named integer constants.
• struct: Used to define a collection of related variables of different data types.



Constant- values that don’t change (fixed)
In computer programming, a constant is a value that cannot be changed during the execution of a
program. Constants are used to represent fixed values that do not need to be modified, such as the value
of pi (3.14159...) or the number of seconds in a minute (60).

In most programming languages, constants are declared using the "const" keyword followed by the data
type and value of the constant. For example, in C programming language, you can declare a constant of
type integer as follows:

const int MY_CONSTANT = 42;

In the C programming language, there are four types of constants:

• Integer constants: These are whole numbers without decimal points. For example, 12, -45, and 0
are integer constants.
• Real constants: These are numbers with decimal points. They can be expressed in scientific
notation, such as 3.14159e-6 or 2.0E8.
• Character constants: These are single characters enclosed in single quotes, such as 'a' or '$'.
• String constants: These are sequences of characters enclosed in double quotes, such as "hello
world".

Additionally, there are two special types of constants:

• Symbolic constants: These are identifiers defined with the #define preprocessor directive. They
represent a value that does not change throughout the program, such as #define PI 3.14159.

Written for

Institution
Course

Document information

Uploaded on
March 3, 2023
Number of pages
26
Written in
2022/2023
Type
OTHER
Person
Unknown

Subjects

$10.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
nitin200411

Get to know the seller

Seller avatar
nitin200411 DBDS
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 year
Number of followers
0
Documents
2
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions