2 - Introduction To 'C' Language
2 - Introduction To 'C' Language
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:
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.