The document discusses various topics related to programming style in C language including tokens, keywords, variables, constants, data types, operators, and flow control statements. It provides definitions and examples of each. Specifically, it defines the different types of tokens in C and gives an example program to demonstrate tokens. It also lists and describes the 32 keywords in C and provides rules for constructing identifiers and variables. Further, it discusses various data types in C including integer, floating-point, and character types and provides their storage sizes and value ranges. The document also covers the different categories of operators in C like arithmetic, relational, logical, bitwise, and assignment operators including their syntax and examples. Finally, it discusses selection and repetition statements like
This document provides an overview of C programming and data structures. It begins with an introduction to C language concepts like data types, variables, constants, I/O functions, operators, and control statements. It then discusses the history and evolution of C from earlier languages like ALGOL and BCPL. The document outlines characteristics of C and its applications. It also covers topics like keywords, identifiers, data type sizes, variable naming rules, and comment syntax. Library functions for input/output like scanf and printf are explained. The different types of constants in C like integer, real, character, and string constants are defined along with their syntax rules.
This document provides an introduction and overview of the C programming language. It discusses the history and development of C, why C is still widely used today despite newer languages, and shows a simple "Hello World" example as a first C program. The document also covers basic C programming concepts like data types, variables, constants, and input/output functions. It provides examples of declaring variables, assigning values, and using the printf statement to output values.
The document provides an introduction to the C programming language. It discusses the structure of a C program including documentation, preprocessor directives, header files, and function definitions. It also describes various math and trigonometric functions available in the standard library like sqrt, pow, sin, cos, and log. The rest of the document outlines the steps to compile and execute a C program and defines key concepts like variables, constants, and data types in C.
This document provides an overview of C programming, including getting started, keywords, identifiers, variables, constants, and data types. It explains that C is an efficient programming language widely used for system and application software. It also covers the basics of compilers, keywords, variables, constants, and different data types like integers, floats, characters, and more. The document is intended for beginners to provide a solid foundation of C programming concepts.
Mca i pic u-2 datatypes and variables in c languageRai University
This document discusses various concepts related to data types and variables in the C programming language. It covers the basic structure of a C program and sections like documentation, definition, global declaration, main function, and subprogram sections. It describes rules for comments, the main method, declaration, data types like integer, floating point, character, and string. It also discusses variables, assigning values, and declaring variables with different storage classes.
Bsc cs i pic u-2 datatypes and variables in c languageRai University
The document discusses various topics related to C programming language including basic structure of a C program, programming rules, comments, main method, declaration, data types, variables, operators, and conditional operators. It provides explanations and examples for each topic. The key points are that a C program contains functions organized into sections, all statements must end with a semicolon, comments are enclosed in /* */ , the main() function contains the main program logic, variables must be declared before use with a specified data type, and operators are used to manipulate variables and perform tasks like arithmetic, comparisons, assignments, and conditionals.
This document provides an overview of C programming and data structures. It begins with an introduction to C language concepts like data types, variables, constants, I/O functions, operators, and control statements. It then discusses the history and evolution of C from earlier languages like ALGOL and BCPL. The document outlines characteristics of C and its applications. It also covers topics like keywords, identifiers, data type sizes, variable naming rules, and comment syntax. Library functions for input/output like scanf and printf are explained. The different types of constants in C like integer, real, character, and string constants are defined along with their syntax rules.
This document provides an introduction and overview of the C programming language. It discusses the history and development of C, why C is still widely used today despite newer languages, and shows a simple "Hello World" example as a first C program. The document also covers basic C programming concepts like data types, variables, constants, and input/output functions. It provides examples of declaring variables, assigning values, and using the printf statement to output values.
The document provides an introduction to the C programming language. It discusses the structure of a C program including documentation, preprocessor directives, header files, and function definitions. It also describes various math and trigonometric functions available in the standard library like sqrt, pow, sin, cos, and log. The rest of the document outlines the steps to compile and execute a C program and defines key concepts like variables, constants, and data types in C.
This document provides an overview of C programming, including getting started, keywords, identifiers, variables, constants, and data types. It explains that C is an efficient programming language widely used for system and application software. It also covers the basics of compilers, keywords, variables, constants, and different data types like integers, floats, characters, and more. The document is intended for beginners to provide a solid foundation of C programming concepts.
Mca i pic u-2 datatypes and variables in c languageRai University
This document discusses various concepts related to data types and variables in the C programming language. It covers the basic structure of a C program and sections like documentation, definition, global declaration, main function, and subprogram sections. It describes rules for comments, the main method, declaration, data types like integer, floating point, character, and string. It also discusses variables, assigning values, and declaring variables with different storage classes.
Bsc cs i pic u-2 datatypes and variables in c languageRai University
The document discusses various topics related to C programming language including basic structure of a C program, programming rules, comments, main method, declaration, data types, variables, operators, and conditional operators. It provides explanations and examples for each topic. The key points are that a C program contains functions organized into sections, all statements must end with a semicolon, comments are enclosed in /* */ , the main() function contains the main program logic, variables must be declared before use with a specified data type, and operators are used to manipulate variables and perform tasks like arithmetic, comparisons, assignments, and conditionals.
The document provides information on the C programming language. It discusses that C was developed by Dennis Ritchie at Bell Labs in 1972 and is a general purpose programming language well suited for business and scientific applications. It describes the basic structure of a C program including sections for links, definitions, variables, functions, and input/output statements. It also covers various C language concepts like data types, operators, decision making statements, looping statements, functions, and more.
C is a powerful, flexible and portable programming language created by Dennis Ritchie in 1972. It supports various data types and has a variety of operators to perform arithmetic, relational, logical and bitwise operations. C programs are compiled into machine-independent code that can run on a variety of hardware and operating system platforms. Key features of C include structured programming, functions, arrays and pointers.
This document provides an overview of basic concepts in C programming including data types, variables, constants, and storage classes. It discusses the basic structure of a C program and sections like main(), functions, and declarations. It describes various data types in C like integer, float, character, and string. Rules for identifiers, keywords, and comments are also covered. The document explains variable declaration and assignment as well as constants like integer, real, character, string and escape sequences. Storage classes and scope of variables are discussed.
Btech i pic u-2 datatypes and variables in c languageRai University
This document discusses various topics related to C programming language including basic structure of a C program, programming rules, comments, main method, declaration, data types, variables, operators, and input/output functions. It explains that a C program contains functions organized into sections like main, documentation, definitions, and subprograms. It provides rules for writing comments, declaring and initializing variables, and defining valid identifiers. It also describes different data types in C like integer, float, character, and string. Finally, it discusses various operators supported in C for arithmetic, relational, logical, assignment, increment/decrement operations.
The C programming language was developed in the 1970s and remains widely used today. It is an efficient, flexible language suitable for system software like operating systems as well as application programs. C has basic elements like keywords, constants, variables, and operators. It defines fundamental data types like integers, floating-point numbers, and characters. C supports a variety of operators for arithmetic, relational, logical, and assignment operations. Variables and constants are declared and defined using rules for naming identifiers and representing numeric, character, string, and escape sequence values.
Here are the values of c in each case:
1. int a = 10, b = 2;
c = 12, 8, 20, 5
2. float a = 10, b = 2;
c = 12, 8, 20, 5
3. int a = 10; float b = 2;
c = 12, 8, 20, 5
The data types of the operands determine the result. For integer operands, the result is an integer. For floating point operands, the result is floating point.
Diploma ii cfpc u-2 datatypes and variables in c languageRai University
The document discusses various topics related to C programming language such as basic structure of a C program, programming rules, comments, main method, declaration, data types, variables, operators, and conditional operators. It explains that a C program consists of functions organized into sections like documentation, definitions, global declarations, main function, and subprograms. It provides rules for writing comments, declaring variables, and defining valid identifiers and constants. It also describes various data types in C including integer, floating point, character, and string types.
C is a programming language created in 1972 at Bell Labs to design the UNIX operating system. It spread quickly due to its power and portability. In 1989, ANSI standardized C to resolve issues from different compiler versions. C is an excellent choice for first programs due to its efficiency, flexibility, portability, and ability to write system software and packages. It has a rich set of data types, operators, and functions and allows extending functionality with custom functions. Variables are names for memory locations that can hold different data types and values.
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...Rowank2
In-depth C programming language interview questions are covered in this post, covering questions on pointers, memory management, data structures, and other advanced subjects. The questions are designed to evaluate the candidate's knowledge of the language's intricacies and sophisticated elements. Candidates can better their language skills and be ready for forthcoming interviews by going through these questions.
The document discusses the basics of the C programming language. It covers topics like C program structure, header files, data types, variables, operators, and more. Some key points:
- C programs are made up of variables, functions, statements, and expressions. Functions enable breaking programs into smaller, more manageable modules.
- Common header files like stdio.h, conio.h, and math.h provide standard input/output functions and mathematical functions.
- C supports basic data types like int, char, float, and double, as well as derived types like pointers, arrays, structures, and unions.
- Operators in C include arithmetic, relational, logical, assignment
The document provides an overview of the C programming language, including its history, basic structure, data types, operators, input/output, decision making, looping, functions, arrays, pointers, strings, structures, file handling, and linked data structures. Some key topics covered include the C compilation process, basic C program structure, common data types like int and char, arithmetic, relational, and logical operators, if/else and switch statements, while, do-while and for loops, defining functions, and passing arguments to functions.
This document discusses constants, variables, and data types in C programming. It defines tokens and keywords as the basic units, and explains constants and variables as values that either remain fixed or can change. Various data types are covered, including primary, user-defined, and derived types, along with modifiers that alter storage capacity. Rules for variable names and declarations are provided. The document also discusses assigning values to variables through constants, multiple assignments, and initialization.
This document provides an overview of variables and constants in C#. It discusses the definition and initialization of variables, including value types like integers, floats, characters and reference types. Constants refer to fixed values that cannot be altered, and include integer, floating point, character and string literals. Various examples are provided of defining and initializing different types of variables and constants in C#.
Fundamentals of C includes tokens contains identifiers, constants, strings, variables, different types of operators, special symbols, data types and type casting in C Language
The document provides an introduction to the C programming language, including its history, features, character sets, tokens, data types, operators, and the basic structure of a C program. It discusses key concepts such as variables, constants, comments, functions, input/output, and how to compile and execute a C program.
The document provides an introduction to the C programming language, including its history, features, character sets, tokens, data types, operators, and the basic structure of a C program. It discusses key concepts such as variables, constants, comments, functions, preprocessing directives, and how to compile and execute a C program.
This document discusses various tokens and language elements in C++ including keywords, identifiers, constants, strings, punctuators, operators, data types, and control structures. It provides details on the different types of constants, keywords, identifiers and their rules. It also explains basic concepts like tokens, expressions, operators, data types and control structures in C++.
C was originally developed in the 1970s by Dennis Ritchie at Bell Labs. It is a high-level, general-purpose programming language that allows for both system and applications programming. C contains features that bridge machine language and high-level languages, making it useful for system programming. The basic elements of C include keywords, variables, constants, operators, and other tokens that are constructed from characters, numbers, and symbols.
C is a widely used general-purpose programming language that can be used to develop complex software like operating systems and databases. It has four basic data types - integer, character, floating-point, and double floating-point. Constants are declared using the const keyword and cannot change value during program execution. Operators perform actions on operands like arithmetic, relational, logical, and assignment operations. Conditional statements and loops allow control flow and repeated execution of code. Header files contain function declarations and macro definitions included using the #include directive. Structures group related variables under a single name. Functions perform specific tasks. Strings are arrays of characters terminated by a null character. C is a mid-level language providing both low-level and high
C is a widely used general-purpose programming language that can be used to develop complex software like operating systems and databases. It supports basic data types like integers, characters, and floating-point values. Constants are declared using the const keyword and cannot change value during program execution. C includes various operators like arithmetic, relational, logical, and bitwise operators to perform operations. Conditional statements and loops allow for control flow and repeated execution of code. Header files contain function declarations and macro definitions that can be included using the #include directive. Structures group related data types under a single name. Functions are blocks of code that perform tasks. Strings are arrays of characters terminated by a null character.
Walmart Business+ and Spark Good for Nonprofits.pdfTechSoup
"Learn about all the ways Walmart supports nonprofit organizations.
You will hear from Liz Willett, the Head of Nonprofits, and hear about what Walmart is doing to help nonprofits, including Walmart Business and Spark Good. Walmart Business+ is a new offer for nonprofits that offers discounts and also streamlines nonprofits order and expense tracking, saving time and money.
The webinar may also give some examples on how nonprofits can best leverage Walmart Business+.
The event will cover the following::
Walmart Business + (https://business.walmart.com/plus) is a new shopping experience for nonprofits, schools, and local business customers that connects an exclusive online shopping experience to stores. Benefits include free delivery and shipping, a 'Spend Analytics” feature, special discounts, deals and tax-exempt shopping.
Special TechSoup offer for a free 180 days membership, and up to $150 in discounts on eligible orders.
Spark Good (walmart.com/sparkgood) is a charitable platform that enables nonprofits to receive donations directly from customers and associates.
Answers about how you can do more with Walmart!"
The document provides information on the C programming language. It discusses that C was developed by Dennis Ritchie at Bell Labs in 1972 and is a general purpose programming language well suited for business and scientific applications. It describes the basic structure of a C program including sections for links, definitions, variables, functions, and input/output statements. It also covers various C language concepts like data types, operators, decision making statements, looping statements, functions, and more.
C is a powerful, flexible and portable programming language created by Dennis Ritchie in 1972. It supports various data types and has a variety of operators to perform arithmetic, relational, logical and bitwise operations. C programs are compiled into machine-independent code that can run on a variety of hardware and operating system platforms. Key features of C include structured programming, functions, arrays and pointers.
This document provides an overview of basic concepts in C programming including data types, variables, constants, and storage classes. It discusses the basic structure of a C program and sections like main(), functions, and declarations. It describes various data types in C like integer, float, character, and string. Rules for identifiers, keywords, and comments are also covered. The document explains variable declaration and assignment as well as constants like integer, real, character, string and escape sequences. Storage classes and scope of variables are discussed.
Btech i pic u-2 datatypes and variables in c languageRai University
This document discusses various topics related to C programming language including basic structure of a C program, programming rules, comments, main method, declaration, data types, variables, operators, and input/output functions. It explains that a C program contains functions organized into sections like main, documentation, definitions, and subprograms. It provides rules for writing comments, declaring and initializing variables, and defining valid identifiers. It also describes different data types in C like integer, float, character, and string. Finally, it discusses various operators supported in C for arithmetic, relational, logical, assignment, increment/decrement operations.
The C programming language was developed in the 1970s and remains widely used today. It is an efficient, flexible language suitable for system software like operating systems as well as application programs. C has basic elements like keywords, constants, variables, and operators. It defines fundamental data types like integers, floating-point numbers, and characters. C supports a variety of operators for arithmetic, relational, logical, and assignment operations. Variables and constants are declared and defined using rules for naming identifiers and representing numeric, character, string, and escape sequence values.
Here are the values of c in each case:
1. int a = 10, b = 2;
c = 12, 8, 20, 5
2. float a = 10, b = 2;
c = 12, 8, 20, 5
3. int a = 10; float b = 2;
c = 12, 8, 20, 5
The data types of the operands determine the result. For integer operands, the result is an integer. For floating point operands, the result is floating point.
Diploma ii cfpc u-2 datatypes and variables in c languageRai University
The document discusses various topics related to C programming language such as basic structure of a C program, programming rules, comments, main method, declaration, data types, variables, operators, and conditional operators. It explains that a C program consists of functions organized into sections like documentation, definitions, global declarations, main function, and subprograms. It provides rules for writing comments, declaring variables, and defining valid identifiers and constants. It also describes various data types in C including integer, floating point, character, and string types.
C is a programming language created in 1972 at Bell Labs to design the UNIX operating system. It spread quickly due to its power and portability. In 1989, ANSI standardized C to resolve issues from different compiler versions. C is an excellent choice for first programs due to its efficiency, flexibility, portability, and ability to write system software and packages. It has a rich set of data types, operators, and functions and allows extending functionality with custom functions. Variables are names for memory locations that can hold different data types and values.
C Language Interview Questions: Data Types, Pointers, Data Structures, Memory...Rowank2
In-depth C programming language interview questions are covered in this post, covering questions on pointers, memory management, data structures, and other advanced subjects. The questions are designed to evaluate the candidate's knowledge of the language's intricacies and sophisticated elements. Candidates can better their language skills and be ready for forthcoming interviews by going through these questions.
The document discusses the basics of the C programming language. It covers topics like C program structure, header files, data types, variables, operators, and more. Some key points:
- C programs are made up of variables, functions, statements, and expressions. Functions enable breaking programs into smaller, more manageable modules.
- Common header files like stdio.h, conio.h, and math.h provide standard input/output functions and mathematical functions.
- C supports basic data types like int, char, float, and double, as well as derived types like pointers, arrays, structures, and unions.
- Operators in C include arithmetic, relational, logical, assignment
The document provides an overview of the C programming language, including its history, basic structure, data types, operators, input/output, decision making, looping, functions, arrays, pointers, strings, structures, file handling, and linked data structures. Some key topics covered include the C compilation process, basic C program structure, common data types like int and char, arithmetic, relational, and logical operators, if/else and switch statements, while, do-while and for loops, defining functions, and passing arguments to functions.
This document discusses constants, variables, and data types in C programming. It defines tokens and keywords as the basic units, and explains constants and variables as values that either remain fixed or can change. Various data types are covered, including primary, user-defined, and derived types, along with modifiers that alter storage capacity. Rules for variable names and declarations are provided. The document also discusses assigning values to variables through constants, multiple assignments, and initialization.
This document provides an overview of variables and constants in C#. It discusses the definition and initialization of variables, including value types like integers, floats, characters and reference types. Constants refer to fixed values that cannot be altered, and include integer, floating point, character and string literals. Various examples are provided of defining and initializing different types of variables and constants in C#.
Fundamentals of C includes tokens contains identifiers, constants, strings, variables, different types of operators, special symbols, data types and type casting in C Language
The document provides an introduction to the C programming language, including its history, features, character sets, tokens, data types, operators, and the basic structure of a C program. It discusses key concepts such as variables, constants, comments, functions, input/output, and how to compile and execute a C program.
The document provides an introduction to the C programming language, including its history, features, character sets, tokens, data types, operators, and the basic structure of a C program. It discusses key concepts such as variables, constants, comments, functions, preprocessing directives, and how to compile and execute a C program.
This document discusses various tokens and language elements in C++ including keywords, identifiers, constants, strings, punctuators, operators, data types, and control structures. It provides details on the different types of constants, keywords, identifiers and their rules. It also explains basic concepts like tokens, expressions, operators, data types and control structures in C++.
C was originally developed in the 1970s by Dennis Ritchie at Bell Labs. It is a high-level, general-purpose programming language that allows for both system and applications programming. C contains features that bridge machine language and high-level languages, making it useful for system programming. The basic elements of C include keywords, variables, constants, operators, and other tokens that are constructed from characters, numbers, and symbols.
C is a widely used general-purpose programming language that can be used to develop complex software like operating systems and databases. It has four basic data types - integer, character, floating-point, and double floating-point. Constants are declared using the const keyword and cannot change value during program execution. Operators perform actions on operands like arithmetic, relational, logical, and assignment operations. Conditional statements and loops allow control flow and repeated execution of code. Header files contain function declarations and macro definitions included using the #include directive. Structures group related variables under a single name. Functions perform specific tasks. Strings are arrays of characters terminated by a null character. C is a mid-level language providing both low-level and high
C is a widely used general-purpose programming language that can be used to develop complex software like operating systems and databases. It supports basic data types like integers, characters, and floating-point values. Constants are declared using the const keyword and cannot change value during program execution. C includes various operators like arithmetic, relational, logical, and bitwise operators to perform operations. Conditional statements and loops allow for control flow and repeated execution of code. Header files contain function declarations and macro definitions that can be included using the #include directive. Structures group related data types under a single name. Functions are blocks of code that perform tasks. Strings are arrays of characters terminated by a null character.
Walmart Business+ and Spark Good for Nonprofits.pdfTechSoup
"Learn about all the ways Walmart supports nonprofit organizations.
You will hear from Liz Willett, the Head of Nonprofits, and hear about what Walmart is doing to help nonprofits, including Walmart Business and Spark Good. Walmart Business+ is a new offer for nonprofits that offers discounts and also streamlines nonprofits order and expense tracking, saving time and money.
The webinar may also give some examples on how nonprofits can best leverage Walmart Business+.
The event will cover the following::
Walmart Business + (https://business.walmart.com/plus) is a new shopping experience for nonprofits, schools, and local business customers that connects an exclusive online shopping experience to stores. Benefits include free delivery and shipping, a 'Spend Analytics” feature, special discounts, deals and tax-exempt shopping.
Special TechSoup offer for a free 180 days membership, and up to $150 in discounts on eligible orders.
Spark Good (walmart.com/sparkgood) is a charitable platform that enables nonprofits to receive donations directly from customers and associates.
Answers about how you can do more with Walmart!"
A workshop hosted by the South African Journal of Science aimed at postgraduate students and early career researchers with little or no experience in writing and publishing journal articles.
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Dr. Vinod Kumar Kanvaria
Exploiting Artificial Intelligence for Empowering Researchers and Faculty,
International FDP on Fundamentals of Research in Social Sciences
at Integral University, Lucknow, 06.06.2024
By Dr. Vinod Kumar Kanvaria
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...PECB
Denis is a dynamic and results-driven Chief Information Officer (CIO) with a distinguished career spanning information systems analysis and technical project management. With a proven track record of spearheading the design and delivery of cutting-edge Information Management solutions, he has consistently elevated business operations, streamlined reporting functions, and maximized process efficiency.
Certified as an ISO/IEC 27001: Information Security Management Systems (ISMS) Lead Implementer, Data Protection Officer, and Cyber Risks Analyst, Denis brings a heightened focus on data security, privacy, and cyber resilience to every endeavor.
His expertise extends across a diverse spectrum of reporting, database, and web development applications, underpinned by an exceptional grasp of data storage and virtualization technologies. His proficiency in application testing, database administration, and data cleansing ensures seamless execution of complex projects.
What sets Denis apart is his comprehensive understanding of Business and Systems Analysis technologies, honed through involvement in all phases of the Software Development Lifecycle (SDLC). From meticulous requirements gathering to precise analysis, innovative design, rigorous development, thorough testing, and successful implementation, he has consistently delivered exceptional results.
Throughout his career, he has taken on multifaceted roles, from leading technical project management teams to owning solutions that drive operational excellence. His conscientious and proactive approach is unwavering, whether he is working independently or collaboratively within a team. His ability to connect with colleagues on a personal level underscores his commitment to fostering a harmonious and productive workplace environment.
Date: May 29, 2024
Tags: Information Security, ISO/IEC 27001, ISO/IEC 42001, Artificial Intelligence, GDPR
-------------------------------------------------------------------------------
Find out more about ISO training and certification services
Training: ISO/IEC 27001 Information Security Management System - EN | PECB
ISO/IEC 42001 Artificial Intelligence Management System - EN | PECB
General Data Protection Regulation (GDPR) - Training Courses - EN | PECB
Webinars: https://pecb.com/webinars
Article: https://pecb.com/article
-------------------------------------------------------------------------------
For more information about PECB:
Website: https://pecb.com/
LinkedIn: https://www.linkedin.com/company/pecb/
Facebook: https://www.facebook.com/PECBInternational/
Slideshare: http://www.slideshare.net/PECBCERTIFICATION
This presentation includes basic of PCOS their pathology and treatment and also Ayurveda correlation of PCOS and Ayurvedic line of treatment mentioned in classics.
How to Setup Warehouse & Location in Odoo 17 InventoryCeline George
In this slide, we'll explore how to set up warehouses and locations in Odoo 17 Inventory. This will help us manage our stock effectively, track inventory levels, and streamline warehouse operations.
it describes the bony anatomy including the femoral head , acetabulum, labrum . also discusses the capsule , ligaments . muscle that act on the hip joint and the range of motion are outlined. factors affecting hip joint stability and weight transmission through the joint are summarized.
How to Make a Field Mandatory in Odoo 17Celine George
In Odoo, making a field required can be done through both Python code and XML views. When you set the required attribute to True in Python code, it makes the field required across all views where it's used. Conversely, when you set the required attribute in XML views, it makes the field required only in the context of that particular view.
বাংলাদেশের অর্থনৈতিক সমীক্ষা ২০২৪ [Bangladesh Economic Review 2024 Bangla.pdf] কম্পিউটার , ট্যাব ও স্মার্ট ফোন ভার্সন সহ সম্পূর্ণ বাংলা ই-বুক বা pdf বই " সুচিপত্র ...বুকমার্ক মেনু 🔖 ও হাইপার লিংক মেনু 📝👆 যুক্ত ..
আমাদের সবার জন্য খুব খুব গুরুত্বপূর্ণ একটি বই ..বিসিএস, ব্যাংক, ইউনিভার্সিটি ভর্তি ও যে কোন প্রতিযোগিতা মূলক পরীক্ষার জন্য এর খুব ইম্পরট্যান্ট একটি বিষয় ...তাছাড়া বাংলাদেশের সাম্প্রতিক যে কোন ডাটা বা তথ্য এই বইতে পাবেন ...
তাই একজন নাগরিক হিসাবে এই তথ্য গুলো আপনার জানা প্রয়োজন ...।
বিসিএস ও ব্যাংক এর লিখিত পরীক্ষা ...+এছাড়া মাধ্যমিক ও উচ্চমাধ্যমিকের স্টুডেন্টদের জন্য অনেক কাজে আসবে ...
1. Problem Solving and Programming using C
UNIT II
Programming Style – Tokens of C, Keywords, Variables, Constants and rules to form variables and
constants, Data Types, Declaration of Variables and initialization, Operators, operator precedence and
associativity, Type conversions.
Flow of Control: Selection: if and if-else Statements, if-else if statement and switch case, nested if,
examples.
Repetition and Unconditional Control Statements: while Statement, do while statement, for
Statement, nested loops, break, continue, goto.
TOPIC 1: TOKENS OF C:
C tokens are the basic buildings blocks in C language which are constructed together
to write a Cprogram.
Each and every smallest individual units in a C program are known as C tokens.
C tokens example program:
int main() main – keyword
{ {,}, (,) – delimiter
int x, y, total; keyword x, y, total – identifier
x = 10, y = 20;
total = x + y;
printf ("Total = %d n", total); main, {, }, (, ), int, x, y, total – tokens
}
C tokens are of six types. They are,
1. Keywords
2. Identifiers
3. Constants
4. Strings
5. Special charaters
6. Operators
Keywords in C language:
Keywords are pre-defined words in a C compiler.
Each keyword is meant to perform a specific function in a C program.
Since keywords are referred names for compiler, they can’t be used as variable name.
C language supports 32 keywords which are given below.
auto else long switch
break enum register typedef
case extern return union
char float short unsigned
const for signed void
continue goto sizeof volatile
default if static while
2. do int struct _Packed
double
2. Identifiers in C language:
Each program elements in a C program are given a name called identifiers.
Names given to identify Variables, functions and arrays are examples for identifiers.
eg. x is a namegiven to integer variable in above program.
Rules for constructing identifier name in C:
1. First character should be an alphabet or underscore.
2. Succeeding characters might be digits or letter.
3. Punctuation and special characters aren’t allowed except underscore.
Identifiers should not be keywords.
3. C constants
C Constants are also like normal variables. But, only difference is, their values can not be
modified by the program once they are defined.
Constants refer to fixed values. They are also called as literals
Constants may be belonging to any of the data type.
Syntax:
const data_type variable_name = value; (or) #define variable_name value
Types of C constant:
1. Integer constants
2. Real or Floating point constants
3. Octal & Hexadecimal constants
4. Character constants
5. String constants
6. Backslash character constants
Constant type data type (Example)
Integer constants
int (53, 762, -478 etc )
unsigned int (5000u, 1000U etc)long int, long
long int (483,647 2,147,483,680)
Real or Floating point constants float (10.456789)
doule (600.123456789)
Octal constant int (Example: 013 /*starts with 0 */)
Hexadecimal constant int (Example: 0x90 /*starts with 0x*/)
character constants char (Example: ‘A’, ‘B’, ‘C’)
string constants char (Example: “ABCD”, “Hai”)
Rules for constructing C constant:
1. Integer Constants in C:
An integer constant must have at least one digit.
It must not have a decimal point.
It can either be positive or negative.
No commas or blanks are allowed within an integer constant.
If no sign precedes an integer constant, it is assumed to be positive.
The allowable range for integer constants is -32768 to 32767.
3. 2. Real constants in C:
A real constant must have at least one digit
It must have a decimal point
It could be either positive or negative
If no sign precedes an integer constant, it is assumed to be positive.
No commas or blanks are allowed within a real constant.
3. Character and string constants in C:
A character constant is a single alphabet, a single digit or a single special symbol
enclosed withinsingle quotes.
The maximum length of a character constant is 1 character.
String constants are enclosed within double quotes.
4. Backslash Character Constants in C:
There are some characters which have special meaning in C language.
They should be preceded by backslash symbol to make use of special function of them.
Given below is the list of special characters and their purpose.
Backslash character Meaning
b Backspace
f Form feed
n New line
r Carriage return
t Horizontal tab
” Double quote
’ Single quote
Backslash
v Vertical tab
a Alert or bell
? Question mark
N Octal constant (N is an octal constant)
XN Hexadecimal constant (N – hex.dcml cnst)
How to use constants in a C program?
We can define constants in a C program in the following ways.
1. By “const” keyword
2. By “#define” preprocessor directive
Variables:
C variable is a named location in a memory where a program can manipulate the
data. This location isused to hold the value of the variable.
The value of the C variable may get change in the program.
C variable might be belonging to any of the data type like int, float, char etc.
Rules for naming C variable:
1. Variable name must begin with letter or underscore.
2. Variables are case sensitive
3. They can be constructed with digits, letters.
4. No special symbols are allowed other than underscore.
5. sum, height, _value are some examples for variable name
4. Declaring & initializing C variable:
Variables should be declared in the C program before to use.
Memory space is not allocated for a variable while declaration. It happens only on variable
definition.
Variable initialization means assigning a value to the variable.
Type Syntax
Variable declaration data_type variable_name;
Example: int x, y, z; char flat, ch;
Variable initialization data_type variable_name = value;
Example: int x = 50, y = 30; char flag = ‘x’, ch=’l’;
Key Differences between Identifier and Variable:
1. Both an identifier and a variable are the names allotted by users to a particular entity in a
program. The identifier is only used to identify an entity uniquely in a program at the time of
execution whereas, a variable is a name given to a memory location, that is used to hold a value.
2. Variable is only a kind of identifier, other kinds of identifiers are function names, class names,
structure names, etc. So it can be said that all variables are identifiers whereas, vice versa is not
true.
As identifier and variable names are user-defined names, it should be taken care that no two identifiers
or no two variable names in a program should be the same. It will create a problem of ambiguity in a
program.
TOPIC 4: DATA TYPES
Data types in c refer to an extensive system used for declaring variables or functions of
different types. The typeof a variable determines how much space it occupies in storage and
how the bit pattern stored is interpreted.
The types in C can be classified as follows –
Integer Types
The following table provides the details of standard integer types with their storage sizes and
valueranges −
5. Type Storage size Value range
char 1 byte -128 to 127 or 0 to 255
unsigned char 1 byte 0 to 255
signed char 1 byte -128 to 127
int 2 or 4 bytes -32,768 to 32,767 or -2,147,483,648 to
2,147,483,647
unsigned int 2 or 4 bytes 0 to 65,535 or 0 to 4,294,967,295
short 2 bytes -32,768 to 32,767
unsigned short 2 bytes 0 to 65,535
long 4 bytes -2,147,483,648 to 2,147,483,647
unsigned long 4 bytes 0 to 4,294,967,295
To get the exact size of a type or a variable on a particular platform, you can use the sizeof
operator. The expressions sizeof(type) yields the storage size of the object or type in bytes.
Floating-Point Types
The following table provide the details of standard floating-point types with storage
sizes and value rangesand their precision −
Type Storage size Value range Precision
float 4 byte 1.2E-38 to 3.4E+38 6 decimal places
double 8 byte 2.3E-308 to 1.7E+308 15 decimal places
long double 10 byte 3.4E-4932 to 1.1E+4932 19 decimal places
TOPIC 5: OPERATORS
Operators in C Language:
C language supports a rich set of built-in operators. An operator is a symbol that tells the
compiler to performcertain mathematical or logical manipulations. Operators are used in
program to manipulate data and variables.
C operators can be classified into following types,
Arithmetic operators
Relational operators
Logical operators
Bitwise operators
Assignment operators
Conditional operators (ternary operator)
Special operators (sizeof (), comma)
Arithmetic operators
C supports all the basic arithmetic operators. The following table shows all the basic arithmetic
operators.
6. Ope
rato
r
Description Synta
x
E
x
+ adds two operands Operand + operand A+B 4+2
- subtract second operands from first Operand - operand A-B 4+2
* multiply two operand Operand * operand A*B 4+2
/ divide numerator by denominator Operand / operand A/B 4+2
% remainder of division Operand % operand A%B 4+2
++ Increment operator increases integer value
byone
operand++,
++operand
A++
++A
4+2
-- Decrement operator decreases integer
valueby one
Operand--
--operand
A--
--A
4+2
Program:
#include<stdio.h>
#include<conio.h>
Void main()
{
int a,b,c,d,e,f,g;
printf(“enter a,b:”);
scanf(“%d%d”,&a,&b);
c=a+b;
printf(“sum of a and b is %d”,c);
d=a-b;
printf(“sbtraction of a and b is %d”,d);
e=a*b;
printf(“multiplication of a and b is %d”,e);
f=a/b;
printf(“division of a and b is %d”,f);
g=a%b;
printf(“modulo of a and b is %d”,g);
}
Relation operators
Relation operators are used to specify the relation between two operands such as greater
than, less than, equalto and etc.
If the relation between two operands is true then the result is one (1) otherwise zero(0).
Assume variable A holds 10 and variable B holds 20 then
Operato
r
Description Example Outp
ut
== Check if two operand are
equal
A==B Is not true gives 0 as output
!= Check if two operand
are notequal.
A!=B Is true gives 1 as output
7. > Check if operand on the
left is greater than operand
on the right
A>B Is not true gives 0 as output
< Check operand on the
left issmaller than right
operand
A<B Is true gives 1 as output
>= check left operand is
greater thanor equal to
right operand
A>=B Is not true gives 0 as output
<= Check if operand on left
is smaller than or equal
to rightoperand
A<=B Is true gives 1 as output
Program:
#include<stdio.h>
#include<conio.h>
Void main()
{
int a,b,; printf(“enter
a,b:”);
scanf(“%d%d”,&a,&b);
printf(“result for greater than relation operator when its true %d”, a>b);
printf(“result for less than relation operator when its true %d”, a<b);
printf(“result for greater than or equal relation operator when its true %d”, a>=b);
printf(“result for less than or equal relation operator when its true %d”, a<=b);
printf(“result for equal relation operator when its true %d”, a==b);
printf(“result for not equal relation operator when its true %d”, a!=b);
}
Logical operators
Logical operators are used to perform operations on more than one expression.
C language supports following 3 logical operators. Suppose a=1 and b=0,
Operator Descripti
on
Example
&& Logical AND:Called Logical AND operator. If both the
operands are non-zero, then the condition becomes true.
(a && b)
isfalse
|| Logical OR: Called Logical OR Operator. If any of the two
operands is non-zero, then the condition becomes true.
(a || b) is
true
! Logical NOT:Called Logical NOT Operator. It is used to
reverse the logicalstate of its operand. If a condition is true,
then Logical NOT operator will make it false.
(!a) is false
Program:
#include<stdio.h>
#include<conio.h> Void
main()
{
int a,b,c,d,e;
8. printf(“enter a,b:”);
scanf(“%d%d”,&a,&b);
c=a&&b;
d=a||b
;e=!a;
printf(“result for logical and is %d”,c);
printf(“result for logical or is %d”,d);
printf(“result for logical not is %d”,e);
}
Bitwise operators:
Bitwiseoperators perform manipulations of data at bit level. These operators also perform
shifting of bits fromright to left. Bitwise operators are not applied to float or double.
Bitwise operator works on bits and perform bit-by-bit operation. The truth tables for &, |, and ^ is
as follows –
Assume variable 'A' holds 60 and variable 'B' holds 13, then –
Operator Descripti
on
Example
& Bitwise AND:Operator copies a bit to the result if it exists in both
operands.
(A & B) =
12, i.e.,
0000 1100
| Bitwise OR: Operator copies a bit if it exists in either operand. (A | B) = 61,
i.e.,0011
1101
^ Bitwise exclusive OR: Operator copies the bit if it is set in one
operand butnot both.
(A ^ B) =
49, i.e.,
0011 0001
~ Binary Ones Complement Operator is unary and has the
effect of 'flipping'bits.
(~A ) = -61,
i.e,.1100
0011 in 2's
compleme
ntform
<< Binary Left Shift:The left operands value is moved left by
the number ofbits specified by the right operand.
A << 2 = 240
i.e., 1111 0000
>> Binary Right Shift: The left operands value is moved right by
the number ofbits specified by the right operand.
A >> 2 = 15
i.e.,
0000 1111
Now let’s see truth table for bitwise &, | and ^
a b a &
b
a |
b
a ^
b
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
The bitwise shift operators shifts the bit value. The left operand specifies the value to be
9. shifted and the rightoperand specifies the number of positions that the bits in the value are
to be shifted. Both operands have the same precedence.
Example:
Assume A = 60 and B = 13 in binary format, they will be
as follows −A = 0011 1100
B = 0000 1101
A&B = 0000 1100
A|B = 0011 1101
A^B = 0011 0001
~A = 1100 0011
Program
#include<stdio.h>
#include<conio.h>
Void main()
{
int a,b,c,d,e,f,g;
printf(“enter a,b:”);
scanf(“%d%d”,&a,&b);
c=a&b;
d=a|b;
e=a^b;
f=a<<4;
g=b>>3;
printf(“result for bitwise and is %d”,c);printf(“result for bitwise or is %d”,d);
printf(“result for bitwise not is %d”,e);printf(“result for left shift is %d”,f);
printf(“result for right shift is %d”,g);
}
Assignment Operators
we explored how results are displayed and how numerical data are stored and processed using
variables andassignment statements.
Assignment operator (=) is used for assignment a value to a variable and for performing
computations.Assignment statement has the syntax:
variable = expression;
Expression is any combination of constants, variables, and function calls that can be evaluated to
yield a result.
Example:
length = 25;
cMyCar = “Mercedes”;
sum = 3 + 7;
10. newtotal = 18.3*amount;
slope = (y2 – y1)/(x2 – x1);
Assignment operators supported by C language are as follows.
Operato
r
Descripti
on
Examp
le
= assigns values from right side operands to left side operand a=b,
c=a+b
+= adds right operand to the left operand and assign the result
to left
a+=b is same as a=a+b
-= subtracts right operand from the left operand and assign
the result toleft operand
a-=b is same as a=a-b
*= mutiply left operand with the right operand and assign
the result toleft operand
a*=b is same as a=a*b
/= divides left operand with the right operand and assign
the result toleft operand
a/=b is same as a=a/b
%= calculate modulus using two operands and assign the
result to leftoperand
a%=b is same as
a=a%b
<<= Left shift AND assignment operator. C <<= 2 is same as C =
C
<< 2
>>= Right shift AND assignment operator. C >>= 2 is same as C =
C
>> 2
&= Bitwise AND assignment operator. C &= 2 is same as C =
C &2
^= Bitwise exclusive OR and assignment operator. C ^= 2 is same as C
= C ^2
|= Bitwise inclusive OR and assignment operator. C |= 2 is same as C = C
| 2
Program:
#include<stdio.
h>
#include<conio
.h> Void
main()
{
int a,b,c,d,e,f,g;
printf(“enter a,b:”);
scanf(“%d%d”,&a,&
b);c+=b;
d-
=a;
e*=b
;
11. a/=2;
printf(“result for assignment operator is
%d”,c); printf(“result for assignment
operator is %d”,d); printf(“result for
assignment operator is %d”,e);
printf(“result for assignment operator is
%d”,a);
}
Special operators
Operato
r
Description Examp
le
sizeof Returns the size of an
variable
sizeof(x) return size of the
variable x
& Returns the address of an
variable
&x ; return address of the
variable x
* Pointer to a variable *x ; will be pointer to a
variable x
Comma Separate variables,
expressions
Int a,b,c;
Conditional operator
It is also known as ternary operator and used to evaluate conditional
expression. Conditional operator returns one value when condition is true
otherwise returns other value.
If condexpr is true ? Then the value isstatement 1 : Otherwise value statement 2.
Program:
#include<stdio.
h>
#include<conio
.h> Void
main()
{
int a,b,c,d,e,f,g;
printf(“enter a,b:”);
scanf(“%d%d”,&a,&b);
c=(a>b)?a:b;
printf(“result for conditional operator is %d”,c);
}
Conditional expression ? statement1 : statement2
12. Increment Operator in C Programming
1. Increment operator is used to increment the current value of variable by adding integer 1.
2. Increment operator can be applied to only variables.
3. Increment operator is denoted by ++.
13. Different Types of Increment Operation
In C Programming we have two types of increment operator i.e Pre-Increment and Post-Increment
Operator.
A. Pre Increment Operator
Pre-increment operator is used to increment the value of variable before using in the
expression. In the Pre-Increment value is first incremented and then used inside the
expression.
b = ++y;
In this example suppose the value of variable ‘y’ is 5 then value of variable ‘b’ will be 6
because the value of ‘y’gets modified before using it in a expression.
Sample program
Output :
Value of a :
11Value of
x: 11
B. Post Increment Operator
Post-increment operator is used to increment the value of variable as soon as after executing
expression completely in which post increment is used. In the Post-Increment value is first
used in a expression and then incremented.
b = x++;
In this example suppose the value of variable ‘x’ is 5 then value of variable ‘b’ will be 5
because old value of ‘x’is used.
Sample program
#include<stdio.h>
void main()
{
int a,x=10;
a = ++x;
printf("Value of a : %d",a);
printf("Value of x : %d",x);
}
#include<stdio.h>
void main()
{
inta,b,x=10;
a = x++;
printf("Value of a : %d",a);
printf("Value of a : %d",x);
}
15. Value of a :
10Value of
x : 11
Decrement Operator in C Programming :
1. Decrement operator is used to decrease the current value of variable by subtracting integer 1.
2. Like Increment operator, decrement operator can be applied to only variables.
3. Decrement operator is denoted by –.
Different Types of Decrement Operation :
When decrement operator used in C Programming then it can be used as pre-decrement or
post-decrementoperator.
A. Pre Decrement Operator
Pre-decrement operator is used to decrement the value of variable before using in the
expression. In the Pre-decrement value is first decremented and then used inside the
expression.
b = --var;
Suppose the value of variable var is 10 then we can say that value of variable ‘var’ is firstly
decremented thenupdated value will be used in the expression.
C Program
Output :
Value of a
: 9Value of
y : 9
B. Post Decrement Operator
Post-decrement operator is used to decrement the value of variable immediatly after
executing expression completely in which post decrement is used. In the Post-decrement
old value is first used in a expression andthen old value will be decrement by 1.
b = var--;
#include<stdio.h>
void main()
{
intb,y=10;
b = --y;
printf("Value of b : %d",b);
printf("Value of y : %d",y);
}
16. Value of variable ‘var’ is 5. Same value will be used in expression and after execution of
expression new valuewill be 4.
17. C Program
Output :
Value of a :
10Value of
x : 9
Operator precedence and associativity:
Symbol (4M) Type of Operation
(2M)
Associativity(2M)
[ ] ( ) . –> postfix ++ and postfix –– Expression Left to right
prefix ++ and prefix –– sizeof & *
+ – ~ !
Unary Right to left
typecasts Unary Right to left
* / % Multiplicative Left to right
+ – Additive Left to right
<< >> Bitwise shift Left to right
< > <= >= Relational Left to right
== != Equality Left to right
& Bitwise-AND Left to right
^ Bitwise-exclusive-OR Left to right
| Bitwise-inclusive-OR Left to right
&& Logical-AND Left to right
|| Logical-OR Left to right
#include<stdio.h>
void main()
{
inta,x=10;
a = x--;
printf("Value of a : %d",a);
printf("Value of x : %d",x);
}
18. ? : Conditional-
expression
Right to left
= *= /= %=
+= –= <<= >>= &=
^= |=
Simple and
compound
assignment
Right to left
, Sequential
evaluation
Left to right
TOPIC 8: EXPRESSION
TYPES
C Programming Expression:
1. In programming, an expression is any legal combination of symbols that represents a value.
2. C Programming provides its own rules of Expression, whether it is legal
expression or illegalexpression. For example, in the C language x+5 is a legal
expression.
3. Every expression consists of at least one operand and can have one or more operators.
4. Operands are values and Operators are symbols that represent particular actions.
Valid C Programming Expression:
C Programming code gets compiled firstly before execution. In the different phases of compiler, c
programmingexpression is checked for its validity.
Expressions Validit
y
a + b Expression is valid since it contain + operator which is binary operator
+ + a + b Invalid Expression
Priority and Expression:
In order to solve any expression we should have knowledge of C Programming Operators and their
priorities.
Types of Expression:
19. In Programming, different verities of expressions are given to the compiler. Expressions can
be classified on thebasis of Position of Operators in an expression –
20. Type Explanati
on
Example
Infix Expression in which Operator is in between Operands a + b
Prefix Expression in which Operator is written before Operands + a b
Postfix Expression in which Operator is written after Operands a b +
Type ConversionsType casting is a way to convert a variable from one data type to another
data type. For example, if you want to store a long value into a simple integer then you can
type cast long to int. You can convert values from one type to another explicitly using the
cast operator. New data type should be mentionedbefore the variable name or value in
brackets which to be typecast.
There are two types of type casting in c language.
1. Implicit conversion:
Implicit conversions do not required any operator for converted. They are
automatically performedwhen a value is copied to a compatible type in program.
Here, the value of a has been promoted from int to double and we have not had to
specify any type-casting operator. This is known as a standard conversion.
Program:
#include<stdio.h>
#include<conio.h>
Void main()
{
int i;
float f;
double d;
long int l;
x=l/i+i*f-d;
printf(“%d”,x);
}
21. 2. Explicit conversion
In c language, many conversions, especially those that imply a different interpretation of
the value, require anexplicit conversion. We have already seen two notations for explicit
type conversion.
Syntax: (data type) expression;
They are not automatically performed when a value is copied to a compatible type in program.
Program:
#include<stdio.
h>
#include<conio
.h> Void
main()
{
int n;
float sum=0;
for(n=1;n<=10;n
++)
sum=sum+1/float
(n);printf(“
%f”,sum);
}
}
In the above example, n declares as integer after that its converted into float so
the result also bein float data type only.
TOPIC 9: FLOW OF CONTROL
Control Flow-Relational Expressions - Logical Operators
Control Structures are those statements that decide the order in which individual statements or
instructions of aprogram are executed or evaluated.
Control Structures are broadly classified into:
1. Conditional statements: Specifies a condition to execute a group of
statements in a program.The control structures, if, if-else, nested if, if else ladder
and switch, belongs to this category.
2. Iterative statements: Executes one or more statements repeatedly until a
condition is met.The control structures: while, do...while, and for loops, belong
to this category.
3. Jump statements: Transfer of control from one part to another within the
program. Ex. goto,break, continue and return.
Selection: if-else Statement, nested
if Single way selection (Simple if
statement)
The if statements executes a simple or compound statements, depending on whether or not an
expression is trueof false.
The syntax
if(conditional expression)
statements; // single statement
if(conditional expression)
{
23. In the preceding syntaxes, a simple or compound statement (block of statements) is executed
when the condition expression is true. Otherwise, the program control passes to next
statement. If the condition expression is false then the C compiler does not do anything.
Note that the condition expression given in parenthesis, must be evaluated as true (non-zero
value) or false (zerovalues). In addition, a compound statement must be provided by opening
and closing braces.
Examples:
if(7) // a non zero value returns
true if(0) //zero value returns
false if(i==0) //True if i=0
other wise False
if(i=0) //false because value of the expression is zero
Program:
#include<stdio
.h>main()
{
int
a,b,c,d;
float
ratio;
printf(“enter a,b,c,d values ”);
scanf(“%d%d%d%d”,&a,&b,&
c,&d);if(c-d!=0)
{
ratio=(float)(a+b)/(float)
(c-d);printf(“the ratio is
%f”,ratio);
}
Output:
Enter a,b,c,d values 11
12 7 5The ratio is
11.500000
Two - way selection (if-else statement)
The basic decision statement in the computer is the two-way selection. If the condition is
true, one or moreaction statements are executed. If the condition is false, then a different
action or set of actions is executed.
Syntax:
if(conditional-expression)
{
}
els
e
{
}
true-block statements;
false-block Statements;
25. Example: write a C code to find biggest of two numbers using if-else statement
#include<stdio
.h>void main()
{
int a,b;
printf(“enter two
values”);
scanf(“%d%d”,&a,&
b);
if(a>b)
{
}
els
e
{
}
}
printf(“%d is Big Value”,a);
printf(“%d is Big Value”,b);
Null else, nested if, examples
Null Else: if else statement does not have any executable statements then it is consider as null
else statement. Soelse part will contain only (;) because it doesn’t have any executable
statements.
The syntax is as follows:
if(test-condition)
{
true-block statements;
}
else;
Example:
if(sal>10000)
{
sal=sal+1000;
}
else;
Nested if statement
When an if-else is included within an if-else, it is known as a nested if statement. The
control of a programmoves into the inner if statements when the outer if statement is
evaluated to be true.
Include one condition within another condition is known as nested if.
26. Syntax of nested if statement:
if (test expression1)
{
if(test expression2)
{
30. example: write a C code to find biggest of two numbers using if-
else statement#include<stdio.h>
void main()
{
int a,b;
printf(“enter two
values”);
scanf(“%d%d”,&a,&
b);
if(a>b)
{
}
els
e
{
}
}
printf(“%d is Big Value”,a);
printf(“%d is Big Value”,b);
Example programs on nested if
Example of nested if statement : write C code to find the biggest of three
number#include<stdio.h>
Void main()
{
int a,b;
printf(“enter three values”);
scanf(“%d%d%d”,&a,&b,&c);
if(a>b)
{
if(a>c)
printf(“Biggest
Number=%d”,a);else
printf(“Biggest number=%d”,c);
}
else
{
if(b>c)
printf(“Biggest
Number=%d”,b);else
printf(“Biggest number=%d”,c);
}
}
Example:
#include<stdio
.h>main()
{
int
password;
char
username;
printf(“enter user
name”);
scanf(“%c”,&userna
me); printf(“enter
32. }
els
e
printf(“Invalid password”);
printf(“invalid user name”);
}
Multi-way selection: switch,
else-if,The switch statement
The switch statement can be used to make multi-way decisions
It is especially good when you have many cases to choose from
There are still situations where you do have to use if statements, however
The Syntax of switch
switch (expression)
{
case (expression) :
Statements;
break;
case (expression):
Statements;
break;
// more cases can go here
default: Statements;
}
The following rules apply to a switch statement −
The expression used in a switch statement must have an integral or enumerated
type, or be of a classtype in which the class has a single conversion function to an
integral or enumerated type.
You can have any number of case statements within a switch. Each case is followed
by the value to becompared to and a colon.
The constant-expression for a case must be the same data type as the variable in
the switch, and itmust be a constant or a literal.
When the variable being switched on is equal to a case, the statements following that
case will executeuntil a break statement is reached.
When a break statement is reached, the switch terminates, and the flow of control
jumps to the nextline following the switch statement.
Not every case needs to contain a break. If no break appears, the flow of control
will fall through tosubsequent cases until a break is reached.
A switch statement can have an optional default case, which must appear at the end
of the switch. Thedefault case can be used for performing a task when none of the
cases is true. No break is needed in the default case.
Flow Diagram
33. Else-if ladder Statement
An if statement can be followed by an optional else if...else statement, which is very
useful to test variousconditions using single if...else if statement.
When using if...else if..else statements, there are few points to keep in mind −
An if can have zero or one else's and it must come after any else if's.
An if can have zero to many else if's and they must come before the else.
Once an else if succeeds, none of the remaining else if's or else's will be tested.
Syntax
The syntax of an if...else if...else statement in C programming
language is −if(expression 1)
{
Statement 1;
}
else if(expression 2)
{
Statement 2;
}
else if(expression 3)
37. Example programs on else if
ladderExample
#include
<stdio.h>void
main ()
{
int a =
100; if( a
== 10 )
{
printf("Value of a is 10n" );
}
else if( a == 20 )
{
printf("Value of a is 20n" );
}
else if( a == 30 )
{
printf("Value of a is 30n" );
}
else
{
printf("None of the values is matchingn" );
}
printf("Exact value of a is: %dn", a );
}
Example:
#include<stdio
.h>main()
{
int marks;
printf(“enter your
marks”);
scanf(“%d”,&marks);
if(marks>=90)
printf(“YOUR GRADE
:An”);else if(marks>=70 &&
marks<90)
printf(“YOUR GRADE:
Bn”);else if(marks>=50 &&
marks<70)
printf(“YOUR GRADE:Cn”);
else
}
printf(“YOUR GRADE: FAILEDn”);