C programming language notes focus on fundamental concepts such as variable declarations, data types, and control structures. This unit covers essential topics including selection structures, repetition statements, and arithmetic expressions. Ideal for students learning C programming, these notes provide a comprehensive overview of the basics necessary for writing effective code. Key examples and explanations help clarify complex concepts, making it a valuable resource for beginners and those preparing for exams.

Key Points

  • Explains variable declarations and data types in C programming.
  • Covers selection structures including if statements and decision-making algorithms.
  • Details repetition statements such as while loops and for loops.
  • Includes examples of arithmetic expressions and their evaluations.
sharanya poosa
37 pages
Language:English
Type:Textbook
sharanya poosa
37 pages
Language:English
Type:Textbook
309
/ 37
UNIT - I: Overview of C:C Language Elements, Variable Declarations and Data Types, Executable Statements,
General Form of a C Program, Arithmetic Expressions, Formatting Numbers in Program Output.
Selection Structures: Control Structures, Conditions, if Statement, if Statements with Compound
Statements, Decision Steps in Algorithms.
Repetition and Loop Statements: Repetition in Programs, Counting Loops and the while Statement,
Computing a Sum or Product in a Loop, for Statement, Conditional Loops, Loop Design, Nested Loops, do-
while Statement.
INTRODUCTION TO C LANGUAGE
C is a structured programming language.
It was developed by M. Dennis Ritchie in 1972 at Bell Laboratories.
It is considered a high-level language because it allows the programmer to concentrate on the problem at
hand and not worry about the machine that the program will be using.
While many languages claim to be machine independent, C is one of the closest to achieving that goal.
That is another reason why it is used by software developers whose applications have to run on many
different hardware platforms.
Structure of a C Program
Before we study the basic building blocks of the C programming language, let us look at a bare minimum C
program structure so that we can take it as a reference in the upcoming chapters.
Hello World Example A C program basically consists of the following parts –
Preprocessor Commands
Functions
Variables
Statements & Expressions
Comments
Let us look at a simple code that would print the words "Hello World" –
#include <stdio.h>
void main()
{
/* my first program in C */
printf("Hello, World!");
getch();
}
Let us take a look at the various parts of the above program
The first line of the program #include <stdio.h> is a preprocessor command, which tells a C compiler
to include stdio.h file before going to actual compilation.
The next line void main() is the main function where the program execution begins.
The next line /*...*/ will be ignored by the compiler and it has been put to add additional comments
in the program. So such lines are called comments in the program.
The next line printf(...) is another function available in C which causes the message "Hello, World!"
to be displayed on the screen.
C Language Elements
To build a house, you need bricks, cement, doors, and windows. Similarly, to build a C program, you need
basic building blocks. These are known as the "elements of C language," and understanding them is the first
step to becoming a programmer.
Here's a simple breakdown of the main C language elements you'll encounter in your programs:
1. The Character Set
This is the basic foundation. The C language is built using a specific set of characters:
Letters: A-Z, a-z
Digits: 0-9
Special Characters: +, -, *, /, =, (, ), {, }, [, ], ;, , \n, etc.
Every piece of code you write will be a combination of these characters.
2. Keywords
Keywords are reserved words in the C language. They have a predefined meaning and a specific purpose.
You cannot use them as names for variables, functions, or anything else. There are only 32 keywords in C
(e.g., int, if, else, for, while, return, void). Think of them as the fundamental commands of the language.
There are 32 keywords in the C programming language. These are reserved words that have a predefined
meaning and cannot be used as identifiers (variable names, function names, etc.).
S. No.
Keyword
S. No.
Keyword
S. No.
Keyword
S. No.
Keyword
1
auto
9
enum
17
short
25
union
2
break
10
extern
18
signed
26
unsigned
3
case
11
float
19
sizeof
27
void
4
char
12
for
20
static
28
volatile
5
const
13
goto
21
struct
29
while
6
continue
14
if
22
switch
30
_Bool
S. No.
Keyword
S. No.
Keyword
S. No.
Keyword
S. No.
Keyword
7
default
15
int
23
typedef
31
_Complex
8
do
16
long
24
return
32
_Imaginary
3. Identifiers
An identifier is a name given by the programmer to a variable, function, array, or any other user-defined
item. You use them to give a unique name to a piece of data or a block of code.
Standard identifiers
Standard identifiers are names that have a predefined meaning in the C language, but unlike keywords, you
can redefine them. However, it's a bad practice and can lead to confusion and errors. They are typically
found in the standard library header files and are used for functions, macros, and types.
Examples: printf, scanf, main, NULL, size_t.
o The name printf is a standard identifier for a function that prints formatted output. While
you could technically declare your own variable or function named printf, doing so would
cause your program to lose access to the standard printf function, leading to unexpected
behavior.
User-Defined Identifiers
User-defined identifiers are names you, the programmer, create to identify variables, functions, arrays,
structures, and other elements in your code. You have complete freedom in naming them, as long as you
follow a few simple rules:
Rules:
o They must begin with a letter (a-z, A-Z) or an underscore (_).
o They can be followed by letters, digits (0-9), or underscores.
o They are case-sensitive (myVar and myvar are considered two different identifiers).
o They cannot be a C keyword (like int, for, if).
Examples:
o student_age
o calculate_area
o _loop_count
4. Data Types
A data type specifies the type of data a variable can hold and the amount of memory it will occupy.
Choosing the right data type is crucial for efficient programming.
/ 37
End of Document
309

FAQs

what are the main elements of C programming unit 1 notes

The main elements of C Programming Unit 1 Notes include language elements and control structures.

  • Character Set: The basic foundation of C programming, including letters, digits, and special characters.
  • Keywords: Reserved words in C with predefined meanings, such as int, if, and for.
  • Identifiers: Names given to variables and functions, following specific naming rules.
  • Data Types: Types of data that variables can hold, including int, float, and char.

how do control structures work in C programming unit 1 notes

Control structures in C programming allow for decision-making and repetition in code execution.

  • Selection Structures: These include if statements that execute code blocks based on conditions.
  • Repetition Structures: Loops such as while and for that repeat code execution until a condition is met.
  • Decision Steps: Algorithms that evaluate conditions to determine the flow of execution.

what are the data types in C programming unit 1 notes

Data types in C programming define the kind of data a variable can hold and the operations that can be performed on it.

  • Primary Data Types: Includes int for integers, float for floating-point numbers, and char for single characters.
  • Derived Data Types: Includes arrays, pointers, and structures.
  • Enumeration: A user-defined data type that consists of a set of named integer constants.

what is the structure of a C program in unit 1 notes

The structure of a C program typically consists of several key components.

  • Preprocessor Commands: Such as #include which include necessary libraries.
  • Main Function: The entry point of the program where execution begins, defined as int main().
  • Variables and Statements: Declarations and executable statements that perform actions.
  • Comments: Lines that provide explanations within the code, ignored by the compiler.

how to use selection structures in C programming unit 1 notes

Selection structures in C allow the program to execute specific blocks of code based on conditions.

  • If Statement: Executes a block of code if the condition evaluates to true.
  • If-Else Statement: Provides an alternative block of code to execute if the condition is false.
  • Nested If Statements: Allows for multiple conditions to be checked in a hierarchical manner.

what are the operators in C programming unit 1 notes

Operators in C programming are symbols that perform operations on variables and values.

  • Arithmetic Operators: Include +, -, *, /, and %.
  • Relational Operators: Used to compare values, such as == and !=.
  • Logical Operators: Combine boolean expressions, including && and ||.

what is an example of a simple C program in unit 1 notes

A simple C program example is the classic 'Hello, World!'.

  • Code: #include <stdio.h>
    int main() {
    printf("Hello, World!");
    return 0;
    }
  • Explanation: This program includes the standard input/output library, defines the main function, and prints a greeting to the console.

how does the while loop work in C programming unit 1 notes

The while loop in C programming executes a block of code as long as a specified condition is true.

  • Initialization: A counter variable is initialized before the loop starts.
  • Condition: The loop continues as long as the condition evaluates to true.
  • Increment: The counter variable is updated within the loop to avoid infinite loops.

what is the purpose of comments in C programming unit 1 notes

Comments in C programming serve to explain and clarify code for human readers.

  • Types of Comments: Single-line comments using // and multi-line comments using /* ... */.
  • Benefits: They improve code readability and help document the logic behind complex code sections.