IT LAB Presentation (Aditya Sharma 23EEACS005).pptx

chabriislive 14 views 23 slides Mar 08, 2025
Slide 1
Slide 1 of 23
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23

About This Presentation

it lab presentation on c


Slide Content

‘C’-Programming for Beginners By- Aditya Sharma (23EEACS005) Computer Science Engineering Govt. Engineering C ollege, Ajmer Submitted To – Mr. Sunil Kumar Khinchi Sir

TABLE OF CONTENTS About C Language 01 History, Features, and Importance of C Language Data types in C 02 Overview of C Data types Tokens in C 03 Basics of C Tokens Operators in C 04 Understanding C operators Functions in C 05 Defining and Using functions in C

01 ABOUT C LANGUAGE

ABOUT C LANGUAGE C language was developed in 1972 by Dennis Ritchie at Bell Labs. It evolved from the earlier language, B, and was designed for system programming, particularly for the UNIX operating system. C's key features include simplicity, efficiency, portability, and flexibility in memory management. C contains certain additional features that allows it to be used at a lower level , acting as bridge between machine language and the high level languages. Its importance lies in its influence on many modern languages like C++, Java, and Python, and its continued use in operating systems, embedded systems, and application development.

02 DATA TYPES IN C

DATA TYPES IN C Data types in C specify the type of data that can be stored in a variable, determining the amount of memory allocated and the operations that can be performed on that data. 1.) Primitive Data Types: int: Represents integers (e.g., int a = 10;) float: Represents single-precision floating-point numbers (e.g., float b = 3.14;) double: Represents double-precision floating-point numbers (e.g., double c = 3.14159;) char: Represents single characters (e.g., char d = 'A’;)

2.) Derived Data Types: Arrays: Collection of elements of the same type (e.g., int arr [5];) Structures: User-defined data types that group different types (e.g., struct Person{ char name[20]; int age; }; ) Unions: Similar to structures but share the same memory location (e.g., union Data { int i ; float f; }; ) Pointers: Variables that store memory addresses (e.g., int * ptr ;) 3.) Enumeration Data Type: Defines named integer constants (e.g., enum Color {RED, GREEN, BLUE};)

03 TOKENS IN C

TOKENS IN C Tokens are the smallest units of a program and are crucial for writing instructions. In short Tokens are the basic building blocks of the program. They consists of: Keywords Identifiers Constants Operators Punctuations Symbols

KEYWORDS Keywords are nothing but system defined identifiers. Keywords are reserved words of the language. They have specific meaning in the language and cannot be used by the programmer as variable or constant names. C is case sensitive, it means these must be used as it is. 32 Keywords in C Programming. auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static while

IDENTIFIERS A 'C' program consists of two types of elements: user-defined and system-defined. An identifier is a name given to these elements. An identifier is a word used by a programmer to name a variable, function, or label. Identifiers consist of letters and digits in any order, except that the first character must be a letter. Both upper and lowercase letters can be used.

CONSTANTS In C, constants are fixed values that do not change during the execution of a program. They are used to represent permanent data, unlike variables whose values can be modified. Constants improve code readability and maintainability by representing meaningful values. Types of constants in C: 1. Integer Constants: Whole numbers without a decimal point (e.g., 10, -25). 2. Floating-Point Constants: Numbers with a decimal point (e.g., 3.14, -0.123). 3. Character Constants: Single characters enclosed in single quotes (e.g., ‘A’, ‘9’). 4. String Constants: A sequence of characters enclosed in double quotes (e.g., “Hello”). 5. Enumeration Constants: Named constant values defined using the ‘ enum ’ keyword. Constants provide clarity and ensure that values remain unmodified throughout the program.

ESCAPE SEQUENCES Sometimes, it is necessary to use characters which cannot be typed or has special m eaning in C programming. For example: newline(enter), tab, question mark etc. In order to use these characters, escape sequence is used. Sequences Character \b Backspace \f Form feed \n Newline \r Return \t Horizontal tab \v Vertical tab \\ Backslash \’ Single quotation mark \" Double quotation mark \? Question mark \0 Null character

04 OPERATORS IN C

INTRODUCTION TO OPERATORS IN C Definition: Operators in C are symbols that perform operations on variables and values. Purpose: They allow manipulation of data and facilitate arithmetic, logical, and comparison operations. Types of Operators: Arithmetic Relational Logical Assignment Bitwise Conditional Special operators (comma, sizeof )

ARITHMETIC OPERATOR Used for basic mathematical calculations. Operators: + (Addition) - (Subtraction) * (Multiplication) / (Division) % (Modulus - remainder of division) Example - int a = 10, b = 5; int sum = a + b; //15

RELATIONAL AND LOGICAL OPERATORS Relational Operators: Compare two values and return true/false. == (Equal to) != (Not equal to) > (Greater than) < (Less than) >= (Greater than or equal to) <= (Less than or equal to) Logical Operators: Combine multiple conditions. && (Logical AND) || (Logical OR) ! (Logical NOT) Example- if (a > b && b >= 0){ // Both conditions are true }

CONDITIONAL (TERNARY) AND SPECIAL OPERATORS Conditional (Ternary) Operator : Shorthand for if-else condition. Syntax: condition ? expr1 : expr2; Example: int max = (a > b) ? a : b; //Gives max of two values Special Operators: sizeof : Returns the size of a data type. Example - int size = sizeof (int); // returns size of int Comma Operator: Allows multiple expressions. Example - i nt x = (a = 1, b = 2); // Assigns 1 to a, 2 to b

05 FUNCTIONS IN C

FUNCTIONS IN C Functions in C are reusable blocks of code designed to perform specific tasks. They help organize code, improve readability, and enable modular programming. Function Definition: Syntax - return_type function_name ( parameter_list ) { // function body } return_type : Data type of the value returned by the function (e.g., int, void). function_name : Identifier used to call the function. parameter_list : Optional parameters passed to the function.

FUNCTIONS IN C Function Declaration (Prototype):Declares the function's name and type before its use, allowing for better organization. Syntax - int add(int a, int b); Function Call : Invoking the function in the program Example - int result = add(5, 10); Benefits of Functions Modularity: Breaks code into smaller, manageable sections. Reusability: Allows functions to be called multiple times, reducing redundancy. Maintainability: Easier to update and debug code by isolating changes.

EXAMPLE OF FUNCTIONS IN C #include < stdio.h > // Function declaration int add(int a, int b); // Function definition int add(int a, int b) { return a + b; // Returns the sum of a and b } int main() { int sum = add(5, 10); // Function call printf ("The sum is: %d\n", sum); return 0; } // Output: The sum is: 15

T H A N K Y O U
Tags