Arrays passed to functions are passed by reference, not by value. When an array is passed to a function, the function receives the address of the first element. Any modifications made to the array elements inside the function are reflected in the original array in memory. Arrays do not need an ampersand (&) when passed to a function. The function prototype only needs to specify the array name without brackets to indicate an array parameter.
The document discusses binary trees and their representations and operations. It defines binary trees as trees where each node has at most two child nodes. It also defines complete binary trees as trees where every node has two children except leaf nodes. The document discusses array and linked representations of binary trees and various traversal operations like preorder, inorder and postorder traversals. It also provides code snippets for inserting and deleting nodes from a binary tree.
This document provides an overview of data types in C programming, including:
1) It describes four main types of data types - fundamental, modifiers, derived, and user defined. Fundamental types include integer, character, float, void. Modifiers change properties of other types. Derived types include arrays and pointers.
2) It explains the integer, float, character, and void fundamental data types in more detail. Integer can be short, int, long. Float and double store numbers in mantissa and exponent. Character represents keyboard characters.
3) Common C data type sizes and value ranges are provided for integer, float, and character types along with their modifiers like short, long, signed, unsigned.
What are the microoperations that our meant for the implementation of various logical circuits are explained here. Check through all the slides and comment or ask if need help to understand more.
1. The document discusses the topics of computer instructions, timing and control, and the instruction cycle for a basic computer.
2. It describes the three instruction code formats used - memory reference, register reference, and input/output. Memory reference instructions use bits to specify an address and addressing mode. Register reference instructions specify an operation on the accumulator register.
3. The instruction cycle consists of four phases - fetch an instruction, decode the instruction, read the effective address if needed, and execute the instruction.
Arrays are a commonly used data structure that store multiple elements of the same type. Elements in an array are accessed using subscripts or indexes, with the first element having an index of 0. Multidimensional arrays can store elements in rows and columns, accessed using two indexes. Arrays are stored linearly in memory in either row-major or column-major order, which affects how elements are accessed.
This document discusses different number systems used in digital techniques. It defines analog and digital signals, with analog having continuous values and digital having a finite set of discrete values. Four main number systems are covered: decimal with base 10, binary with base 2, octal with base 8, and hexadecimal with base 16. Each system's base, symbols used, examples of representations, and how place values determine a number's value are explained. The document aims to introduce students to number systems and their applications in digital contexts.
A nested loop is a loop inside the body of another loop. The document discusses types of nested loops like nested for, while, do-while loops and provides examples to explain the working of nested loops. It also provides sample programs using nested loops to print patterns, find divisors of numbers, and display multiplication tables.
Flag registers, addressing modes, instruction setaviban
This document provides an agenda and details for a discussion on the 8086 microprocessor. It includes sections on flag registers, addressing modes, and the instruction set. The flag register is described as a 16-bit register containing status flags like carry, parity, auxiliary, zero, and sign flags as well as control flags like trap, interrupt, and direction flags. Various addressing modes are explained for accessing operands in memory using registers, offsets, and displacements. The instruction set section lists common instructions and their purposes. Registers on the 8086 like the general purpose, index, stack pointer, and segment registers are defined along with the instruction execution cycle.
1. The document discusses different methods of representing numeric and non-numeric data in computers, including numeric systems like binary, octal, hexadecimal, and different representations of fixed-point and floating-point numbers.
2. It covers topics like signed number representations using signed magnitude, 1's complement, and 2's complement, and describes how arithmetic operations like addition and subtraction are performed using these methods.
3. Floating-point number representation is also discussed, where numbers are represented in the form of a sign, mantissa, and exponent to allow for a wider range of values.
The document discusses C programming functions. It provides examples of defining, calling, and using functions to calculate factorials, Fibonacci sequences, HCF and LCM recursively and iteratively. Functions allow breaking programs into smaller, reusable blocks of code. They take in parameters, can return values, and have local scope. Function prototypes declare their interface so they can be called from other code locations.
The document discusses different types of joins in database systems. It defines natural join, inner join, equi join, theta join, semi join, anti join, cross join, outer join including left, right and full outer joins, and self join. Examples are provided for each type of join to illustrate how they work.
The document discusses constructors and destructors in C++. It defines constructors as special member functions that are used to construct an object's memory and provide initialization. Destructors are special member functions used to destroy an object's memory. The document provides details on the syntax, usage, and types of constructors and destructors. It includes examples to illustrate default constructors, parameterized constructors, copy constructors, and the use of constructors and destructors.
Decision making and branching in c programmingPriyansh Thakar
The document discusses different types of decision making and branching statements in C programming including if, if-else, nested if-else, else-if ladder, switch case, and goto statements. It provides examples of using each statement type to check conditions and execute different blocks of code based on whether the conditions are true or false. Key points covered include the syntax, flow, and use of each statement type to evaluate conditions and direct program flow.
C++ is an object-oriented programming language developed by Bjarne Stroustrup at Bell Labs as an extension of C with the addition of classes. A simple C++ program consists of including header files, defining classes and their functions, and a main function that uses the classes. The program demonstrates input using cin and output using cout to display the sum and average of two numbers entered by the user.
What are variables and keywords in c++Abdul Hafeez
Hi I am Abdul Hafeez ,I made this videos for Beginner and intermediate students, they can easily understand basic structure of c++ programming.
In this lecture students can understand easily:
* what is variables in c++ Programming?
* variables and data types in c++ Programming
* how to declare variables in c++ Programming
* how to initialize variables in c++ Programming
* keywords in c programming
* keywords in c++ programming
* variables and data types in c++ Programming
* size of data types in c++ Programming
* range of data types in c++ programming
* how are variables stored in memory?
C++ tutorials in URDU - HINDI
Basic concepts and advance concepts
The document discusses Boolean expressions and their use in computer programming. It defines Boolean expressions as expressions that evaluate to true or false. Boolean expressions are composed of logical operators like AND, OR, and NOT. The document then discusses different logical operators and their truth tables. It also covers Boolean algebra identities and theorems. Finally, it introduces concepts like minterms, maxterms, sum of products, and product of sums and how Karnaugh maps can be used to simplify Boolean expressions.
1. Constructors in derived classes are executed after the base class constructor. When an object of a derived class is created, the base class constructor is executed first, followed by the derived class constructor.
2. Destructors in a class hierarchy are invoked in the reverse order of constructor execution. The destructor of the class whose constructor was executed last is called first when the object goes out of scope.
3. The document provides examples of constructors and destructors in single inheritance, multiple inheritance, and multilevel inheritance hierarchies. It demonstrates the order of constructor and destructor execution in various scenarios.
This Presentation will Clear the idea of non linear Data Structure and implementation of Tree by using array and pointer and also Explain the concept of Binary Search Tree (BST) with example
03 Linear Arrays Memory Representations .pdfKkSingh64
The document discusses linear arrays and their memory representation. It defines key concepts related to linear arrays like basic terminology, size/length of an array, indexes, upper and lower bounds. It describes how elements of a linear array are stored sequentially in contiguous memory locations. It also covers traversing arrays, insertion and deletion of elements, and searching techniques like linear search and binary search.
The document discusses exception handling in C and C++. It covers exception fundamentals, and techniques for handling exceptions in C such as return values, global variables, goto statements, signals, and termination functions. It also discusses exception handling features introduced in C++ such as try/catch blocks and exception specifications.
Constructors, Destructors, call in parameterized Constructor, Multiple constructor in a class, Explicit/implicit call, Copy constructor, Dynamic Constructors and call in parameterized Constructor
Decision making statements in C programmingRabin BK
The document discusses various decision making statements in C programming language, including if, if-else, if-else if-else, nested if, switch, ternary operator (? :) and goto statements. It provides syntax and examples of each statement type. Key decision making statements covered are if, if-else, if-else if-else for multi-way decisions, switch as a multi-way decision statement, and the ternary operator for two-way decisions. References and queries sections are also included.
The document discusses different types of arrays in C programming language. It defines an array as a fixed-size sequential collection of elements of the same data type. It describes one-dimensional, two-dimensional and multidimensional arrays. For one-dimensional arrays, it provides examples of declaration, initialization at compile-time and run-time. For two-dimensional arrays, it explains the memory layout and initialization syntax. It also lists some applications of arrays.
1. A recursive function is a function that calls itself, either directly or indirectly. It is related to mathematical induction.
2. Examples of inherently recursive functions include calculating factorials and finding terms in the Fibonacci series recursively.
3. Recursive functions require a base or stop condition to return the final value, otherwise the function will keep calling itself indefinitely. Pseudocode and C code examples are provided to find factorials, sum of natural numbers, and Fibonacci series recursively.
This document discusses different types of codes used to encode information for transmission and storage. It begins by explaining that encoding is required to send information unambiguously over long distances and that decoding is needed to retrieve the original information. It then provides reasons for using coding, such as increasing transmission efficiency and enabling error correction. The document proceeds to describe binary coding and how increasing the number of bits allows more items to be uniquely represented. It also discusses properties of good codes like ease of use and error detection. Specific code types are then outlined, including binary coded decimal codes, unit distance codes, error detection codes, and alphanumeric codes. Gray code and excess-3 code are explained as examples.
Constructor is a special member function that initializes objects of a class. Constructors have the same name as the class and do not have a return type. There are two types of constructors: default constructors that take no parameters, and parameterized constructors that allow passing arguments when creating objects. Constructors are automatically called when objects are created to initialize member variables, unlike regular member functions which must be explicitly called.
This PPT is for First year engineering student,It covered all about C Programming according to Rajastha Technical University Kota.
flowchart, pseudo code, Programming Languages and Language Translators, Identifiers, Constants, Variables, Basic Data Types, Operators, Expressions, type casting, Input / Output Statement, Scope Rules and Storage classes, Preprocessor and Macro Substitution.
Flag registers, addressing modes, instruction setaviban
This document provides an agenda and details for a discussion on the 8086 microprocessor. It includes sections on flag registers, addressing modes, and the instruction set. The flag register is described as a 16-bit register containing status flags like carry, parity, auxiliary, zero, and sign flags as well as control flags like trap, interrupt, and direction flags. Various addressing modes are explained for accessing operands in memory using registers, offsets, and displacements. The instruction set section lists common instructions and their purposes. Registers on the 8086 like the general purpose, index, stack pointer, and segment registers are defined along with the instruction execution cycle.
1. The document discusses different methods of representing numeric and non-numeric data in computers, including numeric systems like binary, octal, hexadecimal, and different representations of fixed-point and floating-point numbers.
2. It covers topics like signed number representations using signed magnitude, 1's complement, and 2's complement, and describes how arithmetic operations like addition and subtraction are performed using these methods.
3. Floating-point number representation is also discussed, where numbers are represented in the form of a sign, mantissa, and exponent to allow for a wider range of values.
The document discusses C programming functions. It provides examples of defining, calling, and using functions to calculate factorials, Fibonacci sequences, HCF and LCM recursively and iteratively. Functions allow breaking programs into smaller, reusable blocks of code. They take in parameters, can return values, and have local scope. Function prototypes declare their interface so they can be called from other code locations.
The document discusses different types of joins in database systems. It defines natural join, inner join, equi join, theta join, semi join, anti join, cross join, outer join including left, right and full outer joins, and self join. Examples are provided for each type of join to illustrate how they work.
The document discusses constructors and destructors in C++. It defines constructors as special member functions that are used to construct an object's memory and provide initialization. Destructors are special member functions used to destroy an object's memory. The document provides details on the syntax, usage, and types of constructors and destructors. It includes examples to illustrate default constructors, parameterized constructors, copy constructors, and the use of constructors and destructors.
Decision making and branching in c programmingPriyansh Thakar
The document discusses different types of decision making and branching statements in C programming including if, if-else, nested if-else, else-if ladder, switch case, and goto statements. It provides examples of using each statement type to check conditions and execute different blocks of code based on whether the conditions are true or false. Key points covered include the syntax, flow, and use of each statement type to evaluate conditions and direct program flow.
C++ is an object-oriented programming language developed by Bjarne Stroustrup at Bell Labs as an extension of C with the addition of classes. A simple C++ program consists of including header files, defining classes and their functions, and a main function that uses the classes. The program demonstrates input using cin and output using cout to display the sum and average of two numbers entered by the user.
What are variables and keywords in c++Abdul Hafeez
Hi I am Abdul Hafeez ,I made this videos for Beginner and intermediate students, they can easily understand basic structure of c++ programming.
In this lecture students can understand easily:
* what is variables in c++ Programming?
* variables and data types in c++ Programming
* how to declare variables in c++ Programming
* how to initialize variables in c++ Programming
* keywords in c programming
* keywords in c++ programming
* variables and data types in c++ Programming
* size of data types in c++ Programming
* range of data types in c++ programming
* how are variables stored in memory?
C++ tutorials in URDU - HINDI
Basic concepts and advance concepts
The document discusses Boolean expressions and their use in computer programming. It defines Boolean expressions as expressions that evaluate to true or false. Boolean expressions are composed of logical operators like AND, OR, and NOT. The document then discusses different logical operators and their truth tables. It also covers Boolean algebra identities and theorems. Finally, it introduces concepts like minterms, maxterms, sum of products, and product of sums and how Karnaugh maps can be used to simplify Boolean expressions.
1. Constructors in derived classes are executed after the base class constructor. When an object of a derived class is created, the base class constructor is executed first, followed by the derived class constructor.
2. Destructors in a class hierarchy are invoked in the reverse order of constructor execution. The destructor of the class whose constructor was executed last is called first when the object goes out of scope.
3. The document provides examples of constructors and destructors in single inheritance, multiple inheritance, and multilevel inheritance hierarchies. It demonstrates the order of constructor and destructor execution in various scenarios.
This Presentation will Clear the idea of non linear Data Structure and implementation of Tree by using array and pointer and also Explain the concept of Binary Search Tree (BST) with example
03 Linear Arrays Memory Representations .pdfKkSingh64
The document discusses linear arrays and their memory representation. It defines key concepts related to linear arrays like basic terminology, size/length of an array, indexes, upper and lower bounds. It describes how elements of a linear array are stored sequentially in contiguous memory locations. It also covers traversing arrays, insertion and deletion of elements, and searching techniques like linear search and binary search.
The document discusses exception handling in C and C++. It covers exception fundamentals, and techniques for handling exceptions in C such as return values, global variables, goto statements, signals, and termination functions. It also discusses exception handling features introduced in C++ such as try/catch blocks and exception specifications.
Constructors, Destructors, call in parameterized Constructor, Multiple constructor in a class, Explicit/implicit call, Copy constructor, Dynamic Constructors and call in parameterized Constructor
Decision making statements in C programmingRabin BK
The document discusses various decision making statements in C programming language, including if, if-else, if-else if-else, nested if, switch, ternary operator (? :) and goto statements. It provides syntax and examples of each statement type. Key decision making statements covered are if, if-else, if-else if-else for multi-way decisions, switch as a multi-way decision statement, and the ternary operator for two-way decisions. References and queries sections are also included.
The document discusses different types of arrays in C programming language. It defines an array as a fixed-size sequential collection of elements of the same data type. It describes one-dimensional, two-dimensional and multidimensional arrays. For one-dimensional arrays, it provides examples of declaration, initialization at compile-time and run-time. For two-dimensional arrays, it explains the memory layout and initialization syntax. It also lists some applications of arrays.
1. A recursive function is a function that calls itself, either directly or indirectly. It is related to mathematical induction.
2. Examples of inherently recursive functions include calculating factorials and finding terms in the Fibonacci series recursively.
3. Recursive functions require a base or stop condition to return the final value, otherwise the function will keep calling itself indefinitely. Pseudocode and C code examples are provided to find factorials, sum of natural numbers, and Fibonacci series recursively.
This document discusses different types of codes used to encode information for transmission and storage. It begins by explaining that encoding is required to send information unambiguously over long distances and that decoding is needed to retrieve the original information. It then provides reasons for using coding, such as increasing transmission efficiency and enabling error correction. The document proceeds to describe binary coding and how increasing the number of bits allows more items to be uniquely represented. It also discusses properties of good codes like ease of use and error detection. Specific code types are then outlined, including binary coded decimal codes, unit distance codes, error detection codes, and alphanumeric codes. Gray code and excess-3 code are explained as examples.
Constructor is a special member function that initializes objects of a class. Constructors have the same name as the class and do not have a return type. There are two types of constructors: default constructors that take no parameters, and parameterized constructors that allow passing arguments when creating objects. Constructors are automatically called when objects are created to initialize member variables, unlike regular member functions which must be explicitly called.
This PPT is for First year engineering student,It covered all about C Programming according to Rajastha Technical University Kota.
flowchart, pseudo code, Programming Languages and Language Translators, Identifiers, Constants, Variables, Basic Data Types, Operators, Expressions, type casting, Input / Output Statement, Scope Rules and Storage classes, Preprocessor and Macro Substitution.
The document discusses algorithms, providing definitions and examples of algorithms including Euclid's algorithm for computing the greatest common divisor. It also outlines properties that algorithms must have including finiteness, absence of ambiguity, defined sequence and inputs/outputs. Pseudocode is introduced as a way to express algorithms at a high level for human reading using basic logic structures like sequence, selection, and iteration.
The document discusses different types of controls in Visual Basic, including intrinsic controls found in the toolbox and ActiveX controls loaded via components. It describes menu controls, how to open the menu editor, and various properties that can be set for menu items like caption, checked status, visibility and enabled status. Pop-up menus are described as menus activated by right-clicking.
The document defines key circuit elements like nodes, branches, and loops. It describes Kirchoff's laws for voltage (KVL) and current (KCL) that relate the voltages and currents in a circuit. Examples are given to show applying KVL and KCL to solve for unknown voltages and currents. Series and parallel resistor combinations are also discussed.
The document discusses arrays in C programming. It defines an array as a group of related data items that share a common name, with each item indicated by an index number. One-dimensional arrays can be represented with a single subscript, while multi-dimensional arrays use multiple subscripts to reference elements by row and column. The document also covers declaring, initializing, and accessing arrays, including examples of one-dimensional, two-dimensional, and multi-dimensional arrays in C.
This document discusses arrays in Microsoft Visual Basic 2005. Arrays allow storing and manipulating multiple values of the same type. Arrays must be declared with a specified size or upper bound. Individual elements can then be accessed using an index number. Loops are commonly used to iterate through arrays to apply the same processing to each element or search for matching values. Parallel arrays use corresponding elements of different arrays to logically link related data.
This document provides a tutorial on pointers and arrays in C. It begins by explaining what a pointer is, noting that a pointer variable stores a memory address rather than a value. It discusses how to declare pointer variables and how to assign memory addresses to pointers using the address-of operator (&). It also covers dereferencing pointers using the asterisk (*) operator to access the value at a pointer's memory address. The document then discusses how pointer types allow pointer arithmetic to increment or decrement pointers by the size of the type being pointed to. Finally, it introduces how arrays are related to pointers since arrays can decay to pointers to their first element.
The document discusses the relationship between arrays and pointers in C programming. It explains that arrays store a consecutive series of variables under a single name, and each element of the array has its own unique memory address. Pointers can be used to reference array elements, where the array name represents the base address of the array and pointer arithmetic allows accessing elements. It provides examples of declaring and initializing arrays, accessing elements using pointers, and how pointers can be incremented or decremented to traverse the array.
The document discusses various topics related to software engineering including types of software projects, project stages, analysis stage, software planning models, software design goals and principles, modular design, design documentation, software design methods, implementation, testing strategies, and maintenance. It also briefly mentions current and future trends in software such as .NET, Windows 8, and mobile development.
The document discusses the two main functions of an operating system: 1) It manages the hardware and software resources of the system, ensuring each application has necessary resources while playing nicely with others. 2) It provides a consistent interface for applications to interact with hardware without needing to know hardware details, allowing applications to run across different systems. The operating system acts as an intermediary between applications and hardware, handling resource management and hardware abstraction to provide stability.
This document discusses electrical circuits and Ohm's law. It covers calculating the total resistance of resistors connected in series and parallel. For series resistors, the total resistance is calculated by adding the individual resistances. For parallel resistors, the total resistance is calculated by taking the reciprocal of the sum of the reciprocals of the individual resistances. More resistors in parallel means lower total resistance, while more resistors in series means higher total resistance. The document provides examples of calculating total resistance, current, and voltage in series and parallel circuits.
This document discusses Ohm's law and basic electrical circuit principles. It defines resistance, current, voltage, and other concepts. It explains that Ohm's law states that voltage is directly proportional to current. Kirchhoff's laws are also summarized, including that current is the same in series circuits and the total current into a parallel branch equals the total current out. Examples are provided of calculating resistance using Ohm's law and of the effects of adding components like cells or lamps to series and parallel circuits.
in this presentation i will explain you about Statements & block, If Else, ElseI f, Switch, While Loop, For loop, Do while loop, Break & continue in c++
C++ provides several types of loops to repeat blocks of code, including while, for, do-while, and nested loops. Loop control statements like break, continue, and goto change the normal execution flow. An infinite loop is one whose condition never becomes false, allowing the loop to repeat indefinitely until terminated.
This document discusses loops in C++. It describes the parts of a loop including initialization, test, and update expressions. It explains the functioning of for, while, and do-while loops through examples. A for loop executes a sequence of statements multiple times in an abbreviated form. A while loop repeats statements as long as a condition is true, testing the condition first. A do-while loop evaluates the test expression after executing the loop body, so the body is executed at least once. Nested loops are used to repeat an inner loop multiple times for each iteration of an outer loop.
This document discusses different types of loops and conditional statements in programming. It describes for, while, do-while, and foreach loops. For loops repeat a block of code a specified number of times. While loops repeat as long as a condition is true. Do-while loops execute code once then repeat as long as the condition is true. Foreach loops iterate over elements in an array. The document also covers if, else if, else, and switch conditional statements. If statements execute code if a condition is true, and else executes it if false. Switch compares a value to multiple cases.
Two-dimensional arrays in C++ allow the creation of arrays with multiple rows and columns. A 2D array is initialized and accessed using two indices, one for the row and one for the column. 2D arrays can be processed using nested for loops, with the outer loop iterating through each row and the inner loop iterating through each column. Functions can accept 2D arrays as parameters, but the number of columns must be specified since arrays are stored in row-major order.
This document discusses loops and repetition structures in C++ programming. It defines pretest and posttest loops, and how they are represented in pseudocode, flowcharts, and C++ code using while and for statements. Specific examples are provided, including a commission calculation program using a while loop, and a stock price averaging program using a counter and accumulator in a while loop. Counter-controlled loops are also demonstrated using a for statement.
The document discusses different types of control statements in C programming including decision control statements, iteration statements, and transfer statements. It provides details about if, if-else, switch, while, do-while, for loops. Decision control statements like if, if-else, switch allow altering the flow of execution based on certain conditions. Iteration statements like while, do-while, for are used to repeat a block of code until the given condition is true. They allow looping in a program.
Loop control statements in C are used to repeatedly execute a block of code while or until a given condition is true. There are three main types of loop control statements in C: for, while, and do-while loops. The for loop allows executing a block of code a specific number of times. The while loop repeatedly executes the block as long as the condition is true. The do-while loop is similar to the while loop, but it will always execute the block at least once even if the condition is false.
The document discusses various programming concepts in C# such as random number generation, Boolean expressions, control statements like if/else, switch, for, while and do-while loops. It also covers nested loops, break and continue statements, and provides examples of problems that can be solved using these programming constructs like generating random numbers, printing patterns, and simulating dice rolls.
The document provides an introduction and overview of conditions and loops in C++ programming. It covers arithmetic operations, relational expressions, if/else statements, while loops, do-while loops, and for loops. Examples are given for each concept to demonstrate their syntax and usage. Key topics covered include operators, increment/decrement, if/elseif statements, comparing values, and using loops to repeat blocks of code multiple times.
The document discusses various programming concepts in C# such as data types, control flow statements like if/else, switch, loops (for, while, do-while), methods for generating random numbers, and examples of programming problems involving calculations, patterns, and simulating dice rolls. Random numbers can be generated using the Random class, control structures conditionally execute blocks of code, and loops iterate code for a set number of repetitions.
The document discusses various control statements in C programming like if-else, switch case, for, while, do-while loops and their usage. It explains conditional execution, selection and looping. Examples are given to demonstrate the use of different control statements to check conditions, repeat operations and alter the flow of program execution.
The document discusses loop control structures in C++. It explains the for, while, and do-while loops and provides examples. It also covers break, continue, return, and goto statements used to control program flow in loops.
The document discusses different types of loops in C++ including while, do-while, for, and switch-case statements. It provides examples of using each loop or statement to repeat operations a certain number of times or while a condition is met. Key examples include a countdown loop using while, calculating factorials with for, and a calculator program using switch-case to perform math operations.
Object oriented programming system with C++msharshitha03s
This document provides an overview of C++ control statements, functions, and storage classes. It discusses various loops like while, for, and do-while loops. It also covers decision making statements such as if-else, if-else-if-else, switch statements, and unconditional statements like break, continue, and goto. The document then discusses functions, recursion, and inline functions. Finally, it summarizes different storage classes in C++ like auto, register, static, external, and mutable and provides examples of each.
This document discusses various control structures in C programming language including conditional statements like if-else and switch case, loops like for, while and do-while loops, and jump statements like break, continue, return and goto. It provides examples of each structure and explains their usage and functionality. The key control structures covered are if-else, switch case, for, while, do-while loops, and how to use break, continue, return and goto statements to control program flow in C programs.
This document provides an overview of various programming concepts including variables, data types, decision making statements, loops, and more. It defines variables as named storage areas that can be manipulated by programs. Common variable types like char, int, float, and double are described along with their characteristics. Syntax and examples are given for if/else statements, switch statements, ternary operators, break, continue, and the various loop structures like for, while, and do-while loops. The document concludes by advertising an online programming course offered by Baabtra and providing contact information.
The objective of the Level 5 Diploma in Information Technology is to provide learners with an excellent foundation for a career in a range of organisations. It designed to ensure that each learner is ‘business ready’: a confident, independent thinker with a detailed knowledge of Information Technology, and equipped with the skills to adapt rapidly to change.
The document discusses various control flow statements in C programming such as decision control statements (if, if-else, switch-case), looping statements (for, while, do-while loops), break, continue, goto, and functions. It provides examples of using each statement type and explains their syntax and usage. Key aspects like scope of variables, parameter passing methods (call by value, call by reference), and storage classes (auto, static, extern) related to functions are also covered in the document.
This document discusses loops in C programming. It describes for, while, and do-while loops. The for loop allows code to be executed a specific number of times, specified with an initialization, condition, and increment statement. The while loop repeats code as long as a condition is true. The do-while loop is similar to the while loop, but the code is executed once before checking the condition. The document also discusses counter-controlled and sentinel-controlled loops, and provides examples of each loop type.
The document provides information on control structures in C++ including relational operators, loops, and decisions. It discusses relational operators like ==, <, > that compare values and return true or false. It describes the three types of loops in C++ - for, while, and do-while loops. The for loop executes a fixed number of times based on initialization, test, and increment expressions. The while loop repeats while a test condition is true. The do-while loop executes the body at least once and then repeats while the test condition is true. The document also covers the if statement for simple conditions and if-else for alternative paths, and provides code examples to demonstrate each control structure.
At the end of this lecture students should be able to;
Describe the looping structures in C programming language.
Practice the control flow of different looping structures in C programming language.
Practice the variants in control flow of different looping structures in C programming language.
Apply taught concepts for writing programs.
Fundamental of Information Technology - UNIT 8Shipra Swati
This document discusses different types of control structures in C programming including sequence control, selection/decision control, case control, and repetition/loop control. It provides examples of if, if-else, switch, for, and while loops. The if statement and if-else statement are used for decision making and branching based on a condition being true or false. Switch statements provide an alternative for nested if-else statements. Loops like for and while are used to repeat a block of code until a condition is met. Examples are given to calculate the sum of natural numbers using for and while loops.
The document discusses different control structures in C++ programs that allow for flow of execution. There are three main control structures: sequential, selection, and repetition. The sequential structure executes statements in order without branching. The selection structure (if/else, switch) allows for decisions and choosing between code blocks. The repetition structure (loops) allows code to repeat until a condition is met.
18CSS101J PROGRAMMING FOR PROBLEM SOLVINGGOWSIKRAJAP
The document discusses various operators, control statements, and arrays in C programming. It begins by explaining operator precedence and types of operators such as relational, logical, increment, assignment etc. It then covers control statements including if-else, switch case, for, while, do-while loops. It also discusses goto, break and continue statements. Finally, it describes arrays including initialization, declaration, accessing elements and array operations. The document provides examples to explain the concepts in detail.
Fluid mechanics is the branch of physics concerned with the mechanics of fluids (liquids, gases, and plasmas) and the forces on them. Originally applied to water (hydromechanics), it found applications in a wide range of disciplines, including mechanical, aerospace, civil, chemical, and biomedical engineering, as well as geophysics, oceanography, meteorology, astrophysics, and biology.
It can be divided into fluid statics, the study of various fluids at rest, and fluid dynamics.
Fluid statics, also known as hydrostatics, is the study of fluids at rest, specifically when there's no relative motion between fluid particles. It focuses on the conditions under which fluids are in stable equilibrium and doesn't involve fluid motion.
Fluid kinematics is the branch of fluid mechanics that focuses on describing and analyzing the motion of fluids, such as liquids and gases, without considering the forces that cause the motion. It deals with the geometrical and temporal aspects of fluid flow, including velocity and acceleration. Fluid dynamics, on the other hand, considers the forces acting on the fluid.
Fluid dynamics is the study of the effect of forces on fluid motion. It is a branch of continuum mechanics, a subject which models matter without using the information that it is made out of atoms; that is, it models matter from a macroscopic viewpoint rather than from microscopic.
Fluid mechanics, especially fluid dynamics, is an active field of research, typically mathematically complex. Many problems are partly or wholly unsolved and are best addressed by numerical methods, typically using computers. A modern discipline, called computational fluid dynamics (CFD), is devoted to this approach. Particle image velocimetry, an experimental method for visualizing and analyzing fluid flow, also takes advantage of the highly visual nature of fluid flow.
Fundamentally, every fluid mechanical system is assumed to obey the basic laws :
Conservation of mass
Conservation of energy
Conservation of momentum
The continuum assumption
For example, the assumption that mass is conserved means that for any fixed control volume (for example, a spherical volume)—enclosed by a control surface—the rate of change of the mass contained in that volume is equal to the rate at which mass is passing through the surface from outside to inside, minus the rate at which mass is passing from inside to outside. This can be expressed as an equation in integral form over the control volume.
The continuum assumption is an idealization of continuum mechanics under which fluids can be treated as continuous, even though, on a microscopic scale, they are composed of molecules. Under the continuum assumption, macroscopic (observed/measurable) properties such as density, pressure, temperature, and bulk velocity are taken to be well-defined at "infinitesimal" volume elements—small in comparison to the characteristic length scale of the system, but large in comparison to molecular length scale
This paper proposes a shoulder inverse kinematics (IK) technique. Shoulder complex is comprised of the sternum, clavicle, ribs, scapula, humerus, and four joints.
When we associate semantic rules with productions, we use two notations:
Syntax-Directed Definitions
Translation Schemes
Syntax-Directed Definitions:
give high-level specifications for translations
hide many implementation details such as order of evaluation of semantic actions.
We associate a production rule with a set of semantic actions, and we do not say when they will be evaluated.
Translation Schemes:
indicate the order of evaluation of semantic actions associated with a production rule.
In other words, translation schemes give a little bit information about implementation details.
Passenger car unit (PCU) of a vehicle type depends on vehicular characteristics, stream characteristics, roadway characteristics, environmental factors, climate conditions and control conditions. Keeping in view various factors affecting PCU, a model was developed taking a volume to capacity ratio and percentage share of particular vehicle type as independent parameters. A microscopic traffic simulation model VISSIM has been used in present study for generating traffic flow data which some time very difficult to obtain from field survey. A comparison study was carried out with the purpose of verifying when the adaptive neuro-fuzzy inference system (ANFIS), artificial neural network (ANN) and multiple linear regression (MLR) models are appropriate for prediction of PCUs of different vehicle types. From the results observed that ANFIS model estimates were closer to the corresponding simulated PCU values compared to MLR and ANN models. It is concluded that the ANFIS model showed greater potential in predicting PCUs from v/c ratio and proportional share for all type of vehicles whereas MLR and ANN models did not perform well.
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...Infopitaara
A Boiler Feed Pump (BFP) is a critical component in thermal power plants. It supplies high-pressure water (feedwater) to the boiler, ensuring continuous steam generation.
⚙️ How a Boiler Feed Pump Works
Water Collection:
Feedwater is collected from the deaerator or feedwater tank.
Pressurization:
The pump increases water pressure using multiple impellers/stages in centrifugal types.
Discharge to Boiler:
Pressurized water is then supplied to the boiler drum or economizer section, depending on design.
🌀 Types of Boiler Feed Pumps
Centrifugal Pumps (most common):
Multistage for higher pressure.
Used in large thermal power stations.
Positive Displacement Pumps (less common):
For smaller or specific applications.
Precise flow control but less efficient for large volumes.
🛠️ Key Operations and Controls
Recirculation Line: Protects the pump from overheating at low flow.
Throttle Valve: Regulates flow based on boiler demand.
Control System: Often automated via DCS/PLC for variable load conditions.
Sealing & Cooling Systems: Prevent leakage and maintain pump health.
⚠️ Common BFP Issues
Cavitation due to low NPSH (Net Positive Suction Head).
Seal or bearing failure.
Overheating from improper flow or recirculation.
Value Stream Mapping Worskshops for Intelligent Continuous SecurityMarc Hornbeek
This presentation provides detailed guidance and tools for conducting Current State and Future State Value Stream Mapping workshops for Intelligent Continuous Security.
Data Structures_Linear data structures Linked Lists.pptxRushaliDeshmukh2
Concept of Linear Data Structures, Array as an ADT, Merging of two arrays, Storage
Representation, Linear list – singly linked list implementation, insertion, deletion and searching operations on linear list, circularly linked lists- Operations for Circularly linked lists, doubly linked
list implementation, insertion, deletion and searching operations, applications of linked lists.
PRIZ Academy - Functional Modeling In Action with PRIZ.pdfPRIZ Guru
This PRIZ Academy deck walks you step-by-step through Functional Modeling in Action, showing how Subject-Action-Object (SAO) analysis pinpoints critical functions, ranks harmful interactions, and guides fast, focused improvements. You’ll see:
Core SAO concepts and scoring logic
A wafer-breakage case study that turns theory into practice
A live PRIZ Platform demo that builds the model in minutes
Ideal for engineers, QA managers, and innovation leads who need clearer system insight and faster root-cause fixes. Dive in, map functions, and start improving what really matters.
4. By- Er. Indrajeet Sinha , +919509010997
2.1.1- INTRODUCTION
A control statement is a statement that
determines whether other statements will be
executed.
An if statement decides whether to execute
another statement, or decides which of
two statements to execute.
A loop decides how many times to execute
another statement.
4
5. By- Er. Indrajeet Sinha , +919509010997
C KEYWORDS
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
The words in bold print are used in control statements. They change the
sequential execution of the assignment statements in a function block
6. By- Er. Indrajeet Sinha , +919509010997
C CONTROL STATEMENT
If Statement
If / else statement
For loop
Do loop
Do While Loop
Definition:-
Control statements enable us to specify the flow of program control; ie, the
order in which the instructions in a program must be executed. They make
it possible to make decisions, to perform tasks repeatedly or to jump from
one section of code to another.
7. By- Er. Indrajeet Sinha , +919509010997
2.1.2 - IF SELECTION STRUCTURE
Selection structure
Choose among alternative courses of action
Pseudocode example:
If student’s grade is greater than or equal to 60
Print “Passed”
If the condition is true
Print statement executed, program continues to next
statement
If the condition is false
Print statement ignored, program continues
Indenting makes programs easier to read
8. By- Er. Indrajeet Sinha , +919509010997
IF SELECTION STRUCTURE
Flowchart of pseudocode statement
A decision can be made on
any expression.
zero - false
nonzero - true
Example:
3 - 4 is true
true
false
grade >= 60 print “Passed”
9. By- Er. Indrajeet Sinha , +919509010997
2.1.2- “IF” – “ELSE” WITH A BLOCK OF
STATEMENTS
if (aValue <= 10)
{
printf("Answer is %8.2fn", aValue);
countB++;
} // End if
else
{
printf("Error occurredn");
countC++;
} // End else
10. By- Er. Indrajeet Sinha , +919509010997
2.1.3 IMPORTANCE OF BRACES ( { } )
Curly braces (also referred to as just "braces" or
as "curly brackets") are a major part of the C
programming language.
The main uses of curly braces in:
Functions
void myfunction(datatype argument)
{
statements(s)
}
Loops
Conditional statements
12. By- Er. Indrajeet Sinha , +919509010997
EXAMPLE IF- ELSE
12
// Program to display a number if user enters negative number
// If user enters positive number, that number won't be displayed
#include <stdio.h>
int main()
{
int number;
printf("Enter an integer: ");
scanf("%d", &number);
// Test expression is true if number is less than 0
if (number < 0)
{
printf("You entered %d.n", number);
}
printf("The if statement is easy.");
return 0;
}
Output 1
Enter an integer: -2
You entered -2.
14. By- Er. Indrajeet Sinha , +919509010997
2.1.5- SWITCH STATEMENT
14
Definition:-
A switch statement is a type of selection control
mechanism used to allow the value of a variable or
expression to change the control flow of program
execution via a multiway branch.
A switch statement allows a variable to be tested for
equality against a list of values. Each value is called
a case, and the variable being switched on is
checked for each switch case.
Switch case statements mostly used when we have
number of options (or choices) and we may need to
perform a different task for each choice.
15. By- Er. Indrajeet Sinha , +919509010997
SYNTAX OF SWITCH...CASE
15
switch (n)
{
case constant1:
// code to be executed if n is equal to constant1;
break;
case constant2:
// code to be executed if n is equal to constant2;
break; . . .
default:
// code to be executed if n doesn't match any Constant
}
16. By- Er. Indrajeet Sinha , +919509010997
“SWITCH” STATEMENT
switch (aNumber)
{
case 1 : countA++;
break;
case 10 : countB++;
break;
case 100 :
case 500 : countC++;
break;
default : countD++;
} // End switch
21. By- Er. Indrajeet Sinha , +919509010997
2.2.1 INTRODUCTION OF LOOPS
Definition
Repeats a statement or group of statements
while a given condition is true. It tests the
condition before executing the loop body.
loop. Executes a sequence of statements
multiple times and abbreviates the code that
manages the loop variable.
Loops are used in programming to repeat a
specific block of code. After reading this
tutorial, you will learn to create a for loop in
C programming.
for loop
while loop
do...while loop
21
22. By- Er. Indrajeet Sinha , +919509010997
2.2.2 INITIALIZATION, TEST
CONDITION, INCREMENT AND
DECREMENT OF LOOPS
Note:- A sequence of statements are executed until a specified
condition is true. This sequence of statements to be executed
is kept inside the curly braces { } known as the Loop body.
After every execution of loop body, condition is verified, and if
it is found to be true the loop body is executed again. When
the condition check returns false, the loop body is not
executed.
22
23. By- Er. Indrajeet Sinha , +919509010997
2.2.3- FOR LOOP
A for loop is a repetition control structure that
allows us to efficiently write a loop that needs to
execute a specific number of times.
Syntax
for ( init; condition; increment )
{
statement(s);
}
Here is the flow of control in a 'for' loop −
The init step is executed first, and only once. This
step allows you to declare and initialize any loop
control variables. You are not required to put a
statement here, as long as a semicolon appears.
23
24. By- Er. Indrajeet Sinha , +919509010997
Next, the condition is evaluated. If it is true, the
body of the loop is executed. If it is false, the body of
the loop does not execute and the flow of control
jumps to the next statement just after the 'for' loop.
After the body of the 'for' loop executes, the flow of
control jumps back up to the increment statement.
This statement allows you to update any loop control
variables. This statement can be left blank, as long
as a semicolon appears after the condition.
The condition is now evaluated again. If it is true, the
loop executes and the process repeats itself (body of
loop, then increment step, and then again condition).
After the condition becomes false, the 'for' loop
terminates. 24
26. By- Er. Indrajeet Sinha , +919509010997
EXAMPLE FOR LOOP
#include <stdio.h>
int main ()
{
int a; /* for loop execution */
for( a = 10; a < 20; a = a + 1 )
{
printf("value of a: %dn", a);
}
return 0;
}
26
Out Put:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
27. By- Er. Indrajeet Sinha , +919509010997
for” with a single statement
for” with a block of statements
27
for (i = 1; i <= MAX_LENGTH; i++)
printf("#");
for (i = 0; i < MAX_SIZE; i++)
{
printf("Symbol is %cn", aBuffer[i]);
aResult = aResult / i;
} // End for
29. By- Er. Indrajeet Sinha , +919509010997
2.2.5- WHILE LOOP
A while loop in C programming repeatedly
executes a target statement as long as a given
condition is true.
Syntax
while(condition)
{
statement(s);
}
Here, statement(s) may be a single statement or a block of
statements. The condition may be any expression, and true
is any nonzero value. The loop iterates while the condition is
true.
When the condition becomes false, the program control passes
to the line immediately following the loop.
29
30. By- Er. Indrajeet Sinha , +919509010997
Flow Diagram
30
Here, the key point
to note is that a
while loop might
not execute at all.
When the condition
is tested and the
result is false, the
loop body will be
skipped and the
first statement
after the while loop
will be executed.
31. By- Er. Indrajeet Sinha , +919509010997
Example While Loop
#include <stdio.h>
int main ()
{ /* local variable definition */
int a = 10; /* while loop execution */
while( a < 20 )
{
printf("value of a: %dn", a); a++;
} return 0;
}
31
Out Put:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
32. By- Er. Indrajeet Sinha , +919509010997
2.2.6- DO-WHILE LOOP
Unlike for and while loops, which test the loop condition at
the top of the loop, the do...while loop in C programming
checks its condition at the bottom of the loop.
A do...while loop is similar to a while loop, except the fact
that it is guaranteed to execute at least one time.
Syntax
do
{
statement(s);
} while
Notice that the conditional expression appears at the end of the loop,
so the statement(s) in the loop executes once before the condition is
tested.
If the condition is true, the flow of control jumps back up to do, and
the statement(s) in the loop executes again. This process repeats until
the given condition becomes false.
32
34. By- Er. Indrajeet Sinha , +919509010997
Example
#include <stdio.h>
int main ()
{ /* local variable definition */
int a = 10; /* do loop execution */
do
{
printf("value of a: %dn", a);
a = a + 1;
}while( a < 20 );
return 0;
}
34
Out Put:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
36. By- Er. Indrajeet Sinha , +919509010997
2.2.8 - NESTED LOOPS (FOR,WHILE,DO-
WHILE)
C programming allows to use one loop inside another loop.
On loop nesting is that we can put any type of loop inside
any other type of loop. For example, a 'for' loop can be
inside a 'while' loop or vice versa.
Syntax
The syntax for a nested for loop statement in C is
as follows −
for ( init; condition; increment )
{
for ( init; condition; increment )
{
statement(s);
}
statement(s);
}
36
37. By- Er. Indrajeet Sinha , +919509010997
The syntax for a nested while loop statement in
C programming language is as follows −
while(condition)
{ while(condition)
{
statement(s);
}
statement(s);
}
37
38. By- Er. Indrajeet Sinha , +919509010997
The syntax for a nested do...while loop statement in
C programming language is as follows −
do
{
statement(s);
do
{
statement(s);
}while( condition );
}while( condition );
38
39. By- Er. Indrajeet Sinha , +919509010997
Example
The following program uses a nested for loop to find the prime
numbers from 2 to 100 −
#include <stdio.h>
int main ()
{ /* local variable definition */
int i, j; for(i = 2; i<100; i++)
{
for(j = 2; j <= (i/j); j++)
if(!(i%j))
break; // if factor found, not prime
if(j > (i/j))
printf("%d is primen", i);
}
return 0;
}
39
OutPut:
2 is prime
3 is prime
5 is prime
7 is prime
11 is prime
13 is prime
17 is prime
19 is prime
23 is prime
29 is prime
31 is prime
.
.
.
89 is prime
97 is prime
41. By- Er. Indrajeet Sinha , +919509010997
INTRODUCTION OF LECTURE
What is Array?
Arrays a kind of data structure that can store a fixed-
size sequential collection of elements of the same type.
An array is used to store a collection of data, but it is
often more useful to think of an array as a collection of
variables of the same type.
All arrays consist of contiguous memory locations. The
lowest address corresponds to the first element and the
highest address to the last element.
41
42. By- Er. Indrajeet Sinha , +919509010997
Array – In the C programming language an
array is a fixed sequenced collection of elements
of the same data type. It is simply a grouping of
like type data. In the simplest form, an array can
be used to represent a list of numbers, or a list of
names. Some examples where the concept of an
array can be used:
List of temperatures recorded every hour in a day , or a
month, or a year.
List of employees in an organization
List of products and their cost sold by a store
42
43. By- Er. Indrajeet Sinha , +919509010997
Since an array provides a convenient structure for
representing data, it is classified as one of the data
structures in C language.
There are following types of arrays in the C
programming language –
One – dimensional arrays
Two – dimensional arrays
Multidimensional arrays
43
44. By- Er. Indrajeet Sinha , +919509010997
2.3.1 ONE-DIMENSIONAL ARRAY
Definition
A list of items can be given one variable name using only
one subscript and such a variable is called single sub-
scripted variable or one dimensional array.
2.3.2 Declaration of 1D Arrays –
Like any other variable, arrays must be declared
before they are used so that the compiler can allocate
space for them in the memory. The syntax form of
array declaration is –
Syntax
Datatype arrayName [ arraySize ];
This is called a single-dimensional array.
The arraySize must be an integer constant greater
than zero and type can be any valid C data type.
44
45. By- Er. Indrajeet Sinha , +919509010997
Example –
float height[50];
int groupt[10];
char name[10]
Now as we declare a array
int number[5];
Then the computer reserves five storage locations as the size of
the array is 5 as shown below –
45
46. By- Er. Indrajeet Sinha , +919509010997
Initialization of 1D Array
After an array is declared, it’s elements must be initialized.
In C programming an array can be initialized at either of
the following stages:
At compile time
At run time
Compile Time initialization
We can initialize the elements of arrays in the same was as
the ordinary variables when they are declared. The general
form of initialization of array is:
type array-name[size] = { list of values };The values in the
list are separated by commas. For ex, the statement
int number[3] = { 0,5,4 };
46
47. By- Er. Indrajeet Sinha , +919509010997
Run time Initialization
An array can also be explicitly initialized at run time.
For ex – consider the following segment of a C program.
for(i=0;i<10;i++)
{
scanf(" %d ", &x[i] );
}
Above example will initialize array elements with the values
entered through the keyboard. In the run time initialization of
the arrays looping statements are almost compulsory. Looping
statements are used to initialize the values of the arrays one
by one by using assignment operator or through the keyboard
by the user.
47
48. By- Er. Indrajeet Sinha , +919509010997
Simple C program to store the elements in the array and to print
them from the array.
#include<stdio.h>
void main()
{
int array[5],i;
printf("Enter 5 numbers to store them in array n");
for(i=0;i<5;i++)
{
scanf("%d",&array[i]);
}
printf("Element in the array are - n n");
for(i=0;i<5;i++)
{
printf("Element stored at a[%d] = %d n",i,array[i]);
} getch();
}
48
Input – Enter 5
elements in the array
– 23 45 32 25 45
Output – Elements
in the array are –
Element stored at
a[0]-23
Element stored at
a[0]-45
Element stored at
a[0]-32
Element stored at
a[0]-25
Element stored at
a[0]-45
49. By- Er. Indrajeet Sinha , +919509010997
2.3.4 TWO-DIMENSIONAL ARRAY
Definition
2D Arrays- There could be situations where a table of values will have to be
stored. In such cases 1D arrays are of no use. So we use 2D arrays to
represent the items in tables.
Declaration
syntax –
type array_name [row_size][column_size];
Initializing 2D Array
Like the one dimensional array, 2D arrays can be initialized in both
the two ways; the compile time initialization and the run time
initialization.
Compile Time initialization – We can initialize the elements of
the 2D array in the same way as the ordinary variables are
declared. The best form to initialize 2D array is by using the matrix
form. Syntax is as below –
int table-[2][3] = { { 0, 2, 5} { 1, 3, 0} }; 49
50. By- Er. Indrajeet Sinha , +919509010997
Run Time initialization – As in the initialization of 1D
array we used the looping statements to set the values of the
array one by one.
In the similar way 2D array are initialized by using the
looping structure.
Initialization method –
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&ar1[i][j]);
} }
50
53. By- Er. Indrajeet Sinha , +919509010997
2.11- INTRODUCTION OF LECTURE
Definition
Strings are actually one-dimensional array of
characters terminated by a null character '0'.
In C programming, array of character are
called strings.
53
54. By- Er. Indrajeet Sinha , +919509010997
2.3.7 STRINGS – DECLARATION,
INITIALIZATION, READING,
PRINTING
Declaration and initialization of String
The following declaration and initialization create a
string consisting of the word "Hello". To hold the null
character at the end of the array, the size of the
character array containing the string is one more than
the number of characters in the word "Hello.“
Syntax
char greeting[6] = {'H', 'e', 'l', 'l', 'o', '0'};
OR
char greeting[] = "Hello";
54
55. By- Er. Indrajeet Sinha , +919509010997
Following is the memory presentation of the above
defined string in C
Note: The C compiler automatically places the '0'
at the end of the string when it initializes the
array. 55
57. By- Er. Indrajeet Sinha , +919509010997
2.3.8- STANDARD LIBRARY
FUNCTION OF STRING
57
Note:Where S1 and S2 are two different string.
S.N. Function Purpose
1 strcpy(s1, s2); Copies string s2 into string s1.
2 strcat(s1, s2); Concatenates string s2 onto the end of string
s1.
3 strlen(s1); Returns the length of string s1.
4 strcmp(s1, s2); Returns 0 if s1 and s2 are the same; less than
0 if s1<s2; greater than 0 if s1>s2.
5 strchr(s1, ch); Returns a pointer to the first occurrence of
character ch in string s1.
6 strstr(s1, s2); Returns a pointer to the first occurrence of
string s2 in string s1.
58. By- Er. Indrajeet Sinha , +919509010997
Programming Example
#include <stdio.h>
#include <string.h>
int main ()
{
char str1[12] = "Hello";
char str2[12] = "World";
char str3[12]; int len ; /* copy str1 into str3 */
strcpy(str3, str1);
printf("strcpy( str3, str1) : %sn", str3 ); /* concatenates str1 and str2 */
strcat( str1, str2);
printf("strcat( str1, str2): %sn", str1 ); /* total lenghth of str1 after
concatenation */ len = strlen(str1);
printf("strlen(str1) : %dn", len );
return 0;
}
58
Output:
strcpy( str3, str1) : Hello
strcat( str1, str2):
HelloWorld strlen(str1) : 10
60. By- Er. Indrajeet Sinha , +919509010997
INTRODUCTION TO POINTERS
Definition:
Pointers are variables that hold address of another variable
of same data type.
Benefit of using pointers
Pointers are more efficient in handling Array and Structure.
Pointer allows references to function and thereby helps in
passing of function as arguments to other function.
It reduces length and the program execution time.
It allows C to support dynamic memory management. 60
61. By- Er. Indrajeet Sinha , +919509010997
2.4.1 CONCEPT OF POINTERS
Whenever a variable is declared, system will allocate
a location to that variable in the memory, to hold
value. This location will have its own address number.
Let us assume that system has allocated memory location 80F
for a variable a.
int a = 10 ;
61
62. By- Er. Indrajeet Sinha , +919509010997
We can access the value 10 by either using the variable name a or
the address 80F. Since the memory addresses are simply numbers
they can be assigned to some other variable. The variable that
holds memory address are called pointer variables.
A pointer variable is therefore nothing but a variable that
contains an address, which is a location of another variable. Value
of pointer variable will be stored in another memory location.
62
63. By- Er. Indrajeet Sinha , +919509010997
Declaring a pointer variable
Syntax
data-type *pointer_name;
Note:- Data type of pointer must be same as the variable,
which the pointer is pointing. void type pointer works with
all data types, but isn't used often.
Initialization of Pointer variable
int a = 10 ;
int *ptr ; //pointer declaration
ptr = &a ; //pointer initialization or,
int *ptr = &a ; //initialization and declaration together 63
64. By- Er. Indrajeet Sinha , +919509010997
2.4.3 THE DEREFERENCING
OPERATOR
Once a pointer has been assigned the address of a variable. To
access the value of variable, pointer is dereferenced, using
the indirection operator.
int a,*p; a = 10;
p = &a; printf("%d",*p); //this will print the value of a.
printf("%d",*&a); //this will also print the value of a.
printf("%u",&a); //this will print the address of a.
printf("%u",p); //this will also print the address of a.
printf("%u",&p); //this will also print the address of p.
64
65. By- Er. Indrajeet Sinha , +919509010997
2.4.4 ADDRESS ARITHMETIC
A pointer in c is an address, which is a numeric value.
Therefore, we can perform arithmetic operations on a pointer
just as you can on a numeric value. There are four arithmetic
operators that can be used on pointers: ++, --, +, and –
To understand pointer arithmetic, let us consider
that ptr is an integer pointer which points to the address
1000. Assuming 32-bit integers, let us perform the following
arithmetic operation on the pointer −
ptr++
After the above operation, the ptr will point to the
location 1004 because each time ptr is incremented, it
will point to the next integer location which is 4 bytes
next to the current location. This operation will move the
pointer to the next memory location without impacting
the actual value at the memory location. 65
66. By- Er. Indrajeet Sinha , +919509010997
Incrementing a Pointer
#include <stdio.h>
const int MAX = 3;
int main ()
{
int var[] = {10, 100, 200};
int i, *ptr; /* let us have array address in pointer */
ptr = var;
for ( i = 0; i < MAX; i++)
{
printf("Address of var[%d] = %xn", i, ptr );
printf("Value of var[%d] = %dn", i, *ptr ); /* move to the next location */
ptr++;
}
return 0;
}
66
Output:-
Address of var[0] =
bf882b30 Value of var[0] =
10
Address of var[1] =
bf882b34 Value of var[1] =
100
Address of var[2] =
bf882b38 Value of var[2] =
200
67. By- Er. Indrajeet Sinha , +919509010997
Decrementing a Pointer
#include <stdio.h>
const int MAX = 3;
int main ()
{
int var[] = {10, 100, 200};
int i, *ptr; /* let us have array address in pointer */
ptr = &var[MAX-1];
for ( i = MAX; i > 0; i--)
{
printf("Address of var[%d] = %xn", i-1, ptr );
printf("Value of var[%d] = %dn", i-1, *ptr ); /* move to the previous
location */ ptr--;
}
return 0;
}
67
Output:-
Address of var[2] =
bfedbcd8
Value of var[2] = 200
Address of var[1] =
bfedbcd4
Value of var[1] = 100
Address of var[0] =
bfedbcd0
Value of var[0] = 10
69. By- Er. Indrajeet Sinha , +919509010997
2.5.1 POINTERS TO REPRESENT
ARRAYS
we can use a pointer to point to an Array, and then we can
use that pointer to access the array.
#include <stdio.h>
const int MAX = 3;
int main ()
{
int var[] = {10, 100, 200};
int i, *ptr[MAX];
for ( i = 0; i < MAX; i++)
{
ptr[i] = &var[i]; /* assign the address of integer. */ }
for ( i = 0; i < MAX; i++)
{
printf("Value of var[%d] = %dn", i, *ptr[i] );
}
return 0;
}
69
Output:-
Value of var[0] = 10
Value of var[1] =
100 Value of var[2]
= 200
70. By- Er. Indrajeet Sinha , +919509010997
2.5.2- POINTERS AND STRINGS
Pointer can also be used to create strings. Pointer variables
of char type are treated as string.
Consider
The above creates a string and stores its address in the pointer
variable str. The pointer str now points to the first character
of the string "Hello".
Another important thing to note that string created
using char pointer can be assigned a value at runtime.
char *str; str = "hello"; //this is Legal
The content of the string can be printed
using printf() and puts().
printf("%s", str); puts(str);
Notice: That str is pointer to the string, it is also name of the
string. Therefore we do not need to use indirection operator *.
70
char *str =
"Hello";
71. By- Er. Indrajeet Sinha , +919509010997
We can also have array of pointers. Pointers are very helpful
in handling character array with rows of varying length.
char *name[3]={"Adam“,"chris“,"Deniel”};//Now see same array
without using pointer
char name[3][20]= { "Adam", "chris", "Deniel" };
71
72. By- Er. Indrajeet Sinha , +919509010997
2.5.3 POINTERS TO POINTERS
A pointer to a pointer is a form of multiple indirection, or a chain
of pointers. Normally, a pointer contains the address of a
variable. When we define a pointer to a pointer, the first pointer
contains the address of the second pointer, which points to the
location that contains the actual value as shown below.
A variable that is a pointer to a pointer must be declared as such. This is
done by placing an additional asterisk in front of its name.
For example,
int **var;
72
Pointer-1
Address
Pointer-2
Address
Variable
Value
73. By- Er. Indrajeet Sinha , +919509010997
When a target value is indirectly pointed to by a pointer to a
pointer, accessing that value requires that the asterisk
operator be applied twice, as is shown below in the example
−
#include <stdio.h>
int main ()
{
int var; int *ptr; int **pptr;
var = 3000; /* take the address of var */
ptr = &var; /* take the address of ptr using address of operator & */
pptr = &ptr; /* take the value using pptr */
printf("Value of var = %dn", var );
printf("Value available at *ptr = %dn", *ptr );
printf("Value available at **pptr = %dn", **pptr);
return 0;
}
73
Output:
Value of var = 3000
Value available at *ptr = 3000
Value available at **pptr =
3000
74. By- Er. Indrajeet Sinha , +919509010997
2.5.4 VOID POINTERS
Definition:
The void pointer, also known as the generic pointer, is a
special type of pointer that can be pointed at objects of any data
type. A void pointer is declared like a normal pointer, using
the void keyword as the pointer's type:
void *ptr; // ptr is a void pointer
Void Pointer Basics :
In C General Purpose Pointer is called as void Pointer.
It does not have any data type associated with it
It can store address of any type of variable
A void pointer is a C convention for a raw address.
The compiler has no idea what type of object a void Pointer really points to ?74
75. By- Er. Indrajeet Sinha , +919509010997
Declaration of Void Pointer :
void * pointer_name;
Void Pointer Example :
void *ptr; // ptr is declared as Void pointer
char Cnum;
int inum; float fnum;
ptr = &Cnum; // ptr has address of character data
ptr = &inum; // ptr has address of integer data
ptr = &fnum; // ptr has address of float data
75
76. By- Er. Indrajeet Sinha , +919509010997
Explanation :
void *ptr;
1. Void pointer declaration is shown above.
2. We have declared 3 variables of integer,character and float type.
3. When we assign address of integer to the void pointer, pointer
will become Integer Pointer.
4. When we assign address of Character Data type to void pointer
it will become Character Pointer.
5. Similarly we can assign address of any data type to the void
pointer.
6. It is capable of storing address of any data type
76
77. By- Er. Indrajeet Sinha , +919509010997
Summary : Void Pointer
77
Scenario Behavior
When We assign address of
integer variable to void
pointer
Void Pointer Becomes Integer
Pointer
When We assign address of
character variable to void
pointer
Void Pointer Becomes
Character Pointer
When We assign address of
floating variable to void
pointer
Void Pointer Becomes
Floating Pointer
78. By- Er. Indrajeet Sinha , +919509010997
2.6.1 COMMAND LINE ARGUMENTS
Definition:
It is possible to pass some values from the command line to
our C programs when they are executed. These values are
called command line arguments.
The command line arguments
are handled using main() function arguments
where argc refers to the number of arguments passed,
and argv[] is a pointer array which points to each argument
passed to the program.
78
80. By- Er. Indrajeet Sinha , +919509010997
Following is a simple example
#include <stdio.h>
int main( int argc, char *argv[] )
{
if( argc == 2 )
{
printf("The argument supplied is %sn", argv[1]);
}
else if( argc > 2 )
{
printf("Too many arguments supplied.n");
} else
{
printf("One argument expected.n");
}
}
80
81. By- Er. Indrajeet Sinha , +919509010997
When the above code is compiled and executed with single
argument, it produces the following result.
$./a.out testing The argument supplied is testing
When the above code is compiled and executed with a two
arguments, it produces the following result.
$./a.out testing1 testing2 Too many arguments supplied.
When the above code is compiled and executed without
passing any argument, it produces the following result.
$./a.out One argument expected
NOTE: It should be noted that argv[0] holds the name of the program itself
and argv[1] is a pointer to the first command line argument supplied, and
*argv[n] is the last argument. If no arguments are supplied, argc will be one,
and if you pass one argument then argc is set at 2.
81
83. By- Er. Indrajeet Sinha , +919509010997
2.7.1 DECLARATION OF STRUCTURE
Definition:-
Structure is composition of the different variables of different
data types , grouped under same name. It is user defined data
types in C.
The format of the structure statement is as follows −
struct [structure tag]
{
member definition;
member definition;
...
member definition;
} [one or more structure variables];
Note:-1. Each member declared in Structure is called member.
2. Name given to structure is called as tag
3.Structure member may be of different data type including user
defined data- type also
83
84. By- Er. Indrajeet Sinha , +919509010997
2.7.3 ACCESSING & INITIALIZATION
Accessing Structure Members:
To access any member of a structure, we use the member
access operator (.). The member access operator is coded as a
period between the structure variable name and the structure
member that we wish to access. You would use the
keyword struct to define variables of structure type. The
following example shows how to use a structure in a program −
#include <stdio.h>
#include <string.h>
struct Books
{
char title[50];
char author[50];
char subject[100];
int book_id;
};
84
87. By- Er. Indrajeet Sinha , +919509010997
CONT…
87
Output:
Book 1 title : C Programming
Book 1 author : Nuha Ali
Book 1 subject : C Programming Tutorial
Book 1 book_id : 6495407
Book 2 title : Telecom Billing
Book 2 author : Zara Ali
Book 2 subject : Telecom Billing Tutorial
Book 2 book_id : 6495700
88. By- Er. Indrajeet Sinha , +919509010997
2.7.4 STRUCTURE AND UNION
Definition:
A union is a special data type available in C that allows to
store different data types in the same memory location.
We can define a union with
many members, but only one member can contain a value at
any given time. Unions provide an efficient way of using the
same memory location for multiple-purpose.
o Defining a Union
union [union tag]
{
member definition;
member definition;
...
member definition;
} [one or more Union variables];
88
89. By- Er. Indrajeet Sinha , +919509010997
#include <stdio.h>
#include <string.h>
union Data
{ int i;
float f; char str[20];
};
int main( )
{
union Data data;
data.i = 10;
data.f = 220.5;
strcpy( data.str, "C Programming");
printf( "data.i : %dn", data.i);
printf( "data.f : %fn", data.f);
printf( "data.str : %sn", data.str);
return 0;
}
89
Output:
data.i : 1917853763
data.f :4122360580327794860452759994368.000000
data.str : C Programming
90. By- Er. Indrajeet Sinha , +919509010997
2.7.5 TYPE DEFINITION
Definition
The C programming language provides a keyword
called typedef, which we can use to give a type, a new name.
Following is an example to define a term BYTE for one-byte
numbers −
typedef unsigned char BYTE;
After this type definition, the identifier BYTE can be used
as an abbreviation for the type unsigned char, for
example.
BYTE b1, b2;
By convention, uppercase letters are used for these
definitions to remind the user that the type name is really a
symbolic abbreviation, but we can use lowercase, as follows −
typedef unsigned char byte;
we can use typedef to give a name to our user defined data
types as well.
90
91. By- Er. Indrajeet Sinha , +919509010997
CONT…
For example, we can use typedef with structure to define a
new data type and then use that data type to define
structure variables directly as follows −
#include <stdio.h>
#include <string.h>
typedef struct Books
{
char title[50];
char author[50];
char subject[100];
int book_id;
} Book;
91
93. By- Er. Indrajeet Sinha , +919509010997
93
Output:
Book title : C Programming
Book author : Indrajeet
subject : C Programming Tutorial Book
book_id : 6495407