0% found this document useful (0 votes)
28 views10 pages

BEEE

The document discusses the basics of C programming including an overview of C, why it is used, its data types and sizes, variables, operators, control structures like if/else and loops. It covers topics like constants, variables, data types, operators, if/else statements, switch cases, loops and concludes with discussing C's versatility and importance.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views10 pages

BEEE

The document discusses the basics of C programming including an overview of C, why it is used, its data types and sizes, variables, operators, control structures like if/else and loops. It covers topics like constants, variables, data types, operators, if/else statements, switch cases, loops and concludes with discussing C's versatility and importance.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

BASICS ELECTRONICS AND ELECTRICAL ENGINEERING

NAME: Anisha Devrukhkar


DIV: I SEM:1
URN NO.: 2023-B-10032005A
•Introduction to C Programming:

C programming language was developed in the early 1970s by Dennis Ritchie at


Bell Laboratories. It is a general-purpose, procedural programming language
widely used for developing system software, application software, drivers, and
embedded firmware. C is known for its efficiency, portability, and flexibility.

Why Use C Programming?

1) Efficiency: C allows for direct memory manipulation and offers high


performance, making it suitable for resource-constrained systems.
2) Portability: C programs can run on various platforms with minimal or no
modifications, contributing to its widespread use.
3) Flexibility: C supports both high-level and low-level programming, allowing
programmers to control hardware directly while maintaining a higher level of
abstraction.

Computer Languages:

Low-Level Languages: These languages, like assembly language and machine


code, are closer to hardware and provide more direct control over hardware
resources.

High-Level Languages: Languages like Python, Java, and C++ provide more
abstraction from hardware and offer greater ease of use with higher-level
constructs.
Middle-Level Languages: C falls into this category, as it combines both high-
level and low-level features. It provides access to low-level memory
manipulation while offering higher-level constructs.

Example of a simple c Programming:

#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}

Identifier:
In C programming, an identifier is a name given to a variable, function, array, or
any other user-defined item. It follows specific rules such as starting with a
letter or underscore, followed by letters, digits, or underscores. Identifiers are
case-sensitive.

Basic Data Types and Sizes


C programming language supports various basic data types:

•int: Typically 2 or 4 bytes.


•char: 1 byte.
•float: 4 bytes.
•double: 8 bytes.
•void: Represents absence of type.
The sizes of these data types can vary based on the system's architecture and
compiler used.

Constants and Variables:


•Constants:
Values that remain unchanged during program execution. They can be literals
(like numbers or characters) or defined using the const keyword.
•Variables:
Named storage locations in memory that hold values which can be changed
during program execution. They are declared with a data type and can be
assigned values.

Operators in c programming:
In C programming, operators are symbols used to perform operations on
operands. They can be categorized into various types:

Arithmetic Operators: Perform basic mathematical operations like addition (+),


subtraction (-), multiplication (*), division (/), and more.

Relational Operators: Compare values and return true or false. Examples


include greater than (>), less than (<), equal to (==), not equal to (!=), etc.

Logical Operators: Combine conditions and return true or false. These include
AND (&&), OR (||), and NOT (!).

Assignment Operators: Assign values to variables. For instance, =, +=, -=, *=, /=,
etc.
Bitwise Operators: Perform operations at the bit level. Examples include
bitwise AND (&), bitwise OR (|), bitwise XOR (^), bitwise left shift (<<), bitwise
right shift (>>), etc.

Unary Operators: Operate on a single operand. For example, increment (++),


decrement (--), and address-of (&).

Ternary Operator: ?:, which is a conditional operator that evaluates a condition


and returns one of two values based on whether the condition is true or false.

Logical Operators:
Logical operations are fundamental operations performed on logical values or
variables. Common logical operations include:

AND (Conjunction): Denoted by ∧ or &&, it returns true only if both operands


are true.

OR (Disjunction): Denoted by ∨ or ||, it returns true if at least one operand is


true.

NOT (Negation): Denoted by ¬ or !, it reverses the logical state of its operand. If


true, it returns false, and if false, it returns true.

If else statements in c :
The "if-else" statement is a fundamental control structure in programming
languages like C. It allows you to execute certain code blocks based on specific
conditions.

In C, the basic syntax of the if-else statement is:


if (condition) {
// Code to execute if the condition is true
} else {
// Code to execute if the condition is false
}

Here, condition is a logical expression that evaluates to either true or false. If


the condition is true, the code block inside the if statement is executed. If the
condition is false, the code block inside the else statement (if present) is
executed.

Additionally, you can use multiple else if statements to check for multiple
conditions using the following syntax:

if (condition1) {
// Code to execute if condition1 is true
} else if (condition2) {
// Code to execute if condition2 is true
} else {
// Code to execute if both condition1 and condition2 are false
}

In C programming, the switch statement provides a way to execute different


blocks of code based on the value of an expression.

Here's the basic syntax of a 'switch' statement :


switch (expression) {
case constant1:
// Code to be executed if expression equals constant1
break;
case constant2:
// Code to be executed if expression equals constant2
break;
// Additional cases as needed
default:
// Code to be executed if expression doesn't match any case
}
Here's an example of using switch in C:
int choice:
printf("Enter a number between 1 and 3: ");
scanf("%d", &choice);

switch (choice) {
case 1:
printf("You entered 1.\n");
break;
case 2:
printf("You entered 2.\n");
break;
case 3:
printf("You entered 3.\n");
break;
default:
printf("Invalid choice.\n");
}

In C programming, there are three main types of loops:

for loop: It's used when you know the number of iterations beforehand. It
consists of three parts: initialization, condition, and increment/decrement.

Example:
for (int i = 0; i < 5; i++) {
// Code to be executed repeatedly
}

In C programming, there are three main types of loops:


1)for loop: It's used when you know the number of iterations beforehand. It
consists of three parts: initialization, condition, and increment/decrement.
Example:
for (int i = 0; i < 5; i++) {
// Code to be executed repeatedly
}

2) While loop: This loop iterates as long as a specified condition is true. It tests
the condition before executing the loop body.

Example:
int i = 0;
while (i < 5) {
// Code to be executed repeatedly
i++;
}

3) do-while loop: Similar to a while loop, but it executes the code block once
before checking the condition. It ensures the code block runs at least once.

Example:int i = 0;
do {
// Code to be executed repeatedly
i++;
} while (i < 5);
These loops are fundamental in controlling the flow of execution in C programs,
allowing you to execute code repeatedly based on specific conditions.
In conclusion, C programming is a foundational and versatile language that
remains vital in various domains, from operating systems and embedded
systems to game development and software applications. Its efficiency,
portability, and direct hardware access make it a powerful tool for developers.
Mastering C involves understanding its syntax, memory management, pointers,
and the ability to create efficient algorithms. Embracing C not only provides a
solid programming foundation but also equips developers with skills applicable
across a wide spectrum of technologies and industries.

You might also like