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

2 - Introduction To 'C' Language

Uploaded by

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

2 - Introduction To 'C' Language

Uploaded by

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

IntroductIon to 'c' Language

The C programming language, developed in the early 1970s,


is a powerful and widely-used language that serves as a
foundation for many other programming languages. It is
known for its efficiency, flexibility, and portability. This unit
will cover the essential components of the C language,
including its character set, variables, data types, operators,
control structures, and basic input/output operations.

1. Character Set
The character set of C includes all the valid characters that
can be used in a C program. This consists of:
• Letters: Uppercase (A-Z) and lowercase (a-z).
• Digits: Numbers (0-9).
• Special Characters: Includes punctuation marks like !, @,
#, $, %, ^, &, *, (, ), -, _, =, +, {, }, [, ], ;, :, ’, ", <, >, ,, ., ?, /,
and \.
• Whitespace: Spaces, tabs, and newline characters that
separate tokens in the code.
2. Variables and Identifiers
• Variables: A variable is a named storage location in
memory that holds a value. The value of a variable can
change during program execution.
• Identifiers: Identifiers are names used to identify
variables, functions, arrays, and other entities. They
must begin with a letter or underscore and can be
followed by letters, digits, or underscores. Identifiers are
case-sensitive in C (e.g., Variable and variable are
different).
3. Data Types
Data types define the type of data a variable can hold. In C,
the primary data types include:
• Integer (int): Represents whole numbers.
• Floating Point (float, double): Used for decimal
numbers.
• Character (char): Holds a single character.
• Void: Indicates no value.
These data types can also be modified with qualifiers like
signed, unsigned, short, and long.
4. Constants
Constants are fixed values that do not change during the
execution of a program. They can be of various types, such as:
• Integer Constants: Whole numbers, e.g., 100, -45.
• Floating-Point Constants: Decimal numbers, e.g., 3.14, -
0.001.
• Character Constants: Enclosed in single quotes, e.g., 'A',
'z'.
• String Constants: Enclosed in double quotes, e.g., "Hello,
World!".
5. Operators
Operators are symbols that perform operations on variables
and values. C provides several types of operators:

• Arithmetic Operators: Used for mathematical


operations like addition (+), subtraction (-),
multiplication (*), division (/), and modulus (%).
• Relational Operators: Used to compare two values,
returning true or false. Examples include equal to (==),
not equal to (!=), greater than (>), less than (<), greater
than or equal to (>=), and less than or equal to (<=).
• Logical Operators: Used to perform logical operations:
AND (&&), OR (||), and NOT (!).
• Assignment Operators: Used to assign values to
variables, such as the basic assignment (=) and
compound assignments like +=, -=, etc.
6. Expressions
An expression is a combination of variables, constants, and
operators that evaluates to a value. For example, a + b is an
expression where a and b are variables, and the result is their
sum.
7. Assignments
Assignments involve giving a variable a value using the
assignment operator (=). For example, x = 10; assigns the
value 10 to the variable x.
8. Basic Input/Output Statements
C provides standard functions for input and output
operations:
• Input: The scanf function is used to read data from the
keyboard. For example, scanf("%d", &num); reads an
integer and stores it in the variable num.
• Output: The printf function displays output on the
screen. For example, printf("Hello, World!"); prints
"Hello, World!" to the console.
9. Control Structures
Control structures determine the flow of execution in a
program. C includes various control structures, such as
decision-making statements and loops.

a) Decision-Making Statements
• if Statement: Executes a block of code if a specified
condition is true.
• if-else Statement: Provides an alternative block of code
to execute if the condition is false.
• Nested if-else Statements: Allows multiple conditions to
be evaluated by nesting if-else statements.
• Switch Statement: A multi-way branch statement that
allows the execution of code based on the value of a
variable.
b) Loops
Loops are used to execute a block of code multiple times
based on a condition.
• while Loop: Continues to execute as long as a specified
condition is true.
• do-while Loop: Similar to the while loop, but it
guarantees at least one execution of the block before
checking the condition.
• for Loop: Used for iterating a specific number of times,
typically using an initialization, condition, and
increment/decrement in one line.
• Nesting of Loops: You can place one loop inside another
to perform more complex iterations.
10. Simple 'C' Programs
Writing simple C programs helps solidify the understanding of
syntax and structure. A basic C program typically includes:
1. Preprocessor Directives: Such as #include <stdio.h>,
which allows the use of standard input/output functions.
2. Main Function: The entry point of every C program,
defined as int main().
3. Variable Declaration: Declaring variables that will be
used in the program.
4. Statements and Expressions: The logic of the program is
executed through statements.
5. Return Statement: Indicates the end of the program and
returns control to the operating system.
Conclusion
The C programming language provides a solid foundation for
understanding computer programming. By familiarizing
yourself with its character set, variables, data types,
operators, control structures, and basic input/output
operations, you will develop essential skills for writing
efficient programs. Mastery of these concepts not only
prepares you for more advanced programming languages but
also enhances your problem-solving abilities in computer
science. Understanding these fundamental principles is
crucial for your success in the BCA program and beyond.

You might also like