Posts

Decision making statements and Switch Statements

  Decision Making Statements In decision control statements( if else and nested if ), group of statements are executed when condition is true. If condition is false, then else part statements are executed. There are 3 types of decision making control statements in C language. They are, 1. if statements 2. if else statements 3. nested if statements Decision Making Statements - Syntax S.No if statement if…else statement nested if 1.Syntax if(condition) { Statements; } if(condition) { Statement1; Statement2; } else { Statement3; Statement4; } Decision Making Statements - if Example program for if: In “if” control statement, respective block of code is executed when condition is true. main() { int m=40,n=40; if (m == n) { printf("m and n are equal"); } } Output: m and n are equal Decision Making Statements - if else Example program for C – if else: In C if else control statement, group of statements are executed when condition is true. If condition is false, then else part statem...
  Input/output statements, Assignment statements           There are some library functions which are available for transferring the information between the computer and the standard input and output devices. These functions are related to the symbolic constants and are available in the header file. In C Language input and output functions are available as C compiler functions or C library provided with each C compiler implementation. These all functions are collectively known as Standard I/O Library functions. stdin : This file is used to receive the input (usually is keyboard file, but can also take input from the disk file). stdout : This file is used to send or direct the output (usually is a monitor file, but can also send the output to a disk file or any other device). stderr : This file is used to display or store error messages. Types of input/output function: Input output functions in C programming fall into two categories, namely, formatte...

Storage Class

Image
  STORAGE CLASSES ● Storage classes are used to define the scope (visibility) and life-time of variables and/or functions ● Every variable and function in C has two attributes: type and storage class. ● There are four storage classes: • auto • static • extern or global • register THE AUTO STORAGE CLASS : The auto keyword is applied to all local variables automatically. It is the default storage class that is why it is known as automatic variable. EXAMPLE PROBLEM: #include<stdio.h> int main() { int a=10; auto int b=10;//same like above printf("%d %d",a,b); return 0; } Output: 10 10 The register storage class : ● Is used to define local variables that should be stored in a register instead of RAM ● Variable has a maximum size equal to the register size (usually one word) ● Can't have the unary '&' operator applied to it (as it does not have a memory location). { register int miles; } ● The register should only be used for variables that require quick ac...

operators in c

  OPERATORS & EXPRESSIONS An operator is a symbol that tells the compiler to perform a certain mathematical or logical manipulation. Operators are used in programs to manipulate data and variables. Expressions combine variables and constants to produce new values. Categories of Operators 1. Arithmetic Operators 2. Logical Operators 3. Relational Operators 4. Increment and Decrement Operators 5. Assignment operators 6. Bitwise Operators 7. Other Operators - Comma Operator, sizeof operator, ternary operator ?:, reference operator &, dereference operator * , member selection operators ARIHMEIC OPERATOR: Operator: +           addition or unary plus -           subtraction or unary minus *           multiplication ; /           division %         remainder after division                (modul...
  INTRODUCTION OF CONSTANTS INTRODUCTION ❖ Constants in C are the fixed values that are used in a program, and its value remains the same during the entire execution of the program. ❖ Constants are also called literals. ❖ Constants can be any of the data types. ❖ It is considered best practice to define constants using only upper-case names. ❖ Syntax: const type constant_name; const keyword defines a constant in C. Example Program for Constants #include<stdio.h> main() { const int SIDE = 10; int area; area = SIDE*SIDE; printf("The area of the square with side: %d is: %d sq. units" , SIDE, area); } Output The area of the square with side:10 is:100 sq. units Types of Constants Constants Types in C ❖ Constants are categorized into two basic types, and each of these types has its subtypes/categories. These are: ❖ Primary Constants ❖ Numeric Constants 􀀀 Integer Constants 􀀀 Real Constants ❖ Character Constants 􀀀 Single Character Constants 􀀀 String Constants 􀀀 Backslash...

Data types in C

Image
DATA TYPES The data type, of a variable determines a set of values that a variable might take and a set of operations that can be applied to those values. Data type refer to the type and size of data associated with the variable and functions. C language supports 2 different type of data types 1. Primary data types: These are fundamental data types in C namely integer(int), floating point(float), character(char) and void. 2. Derived data types: Derived data types are nothing but primary data types but a little twisted or grouped together like array, structure, union and pointer. INTEGER TYPE ● Integer data type allows a variable to store numeric values. ● “int” keyword is used to refer integer data type. ● The storage size of int data type is 2 or 4 or 8 byte. ● It varies depend upon the processor in the CPU that we use. If we are using 16 bit processor, 2 byte (16 bit) of memory will be allocated for int data type. ● Likewise, 4 byte (32 bit) of memory for 32 bit processor and 8 byte...

Introduction of C Programming

  Introduction of C Introduction ❖ C is a general--purpose, high--level language developed by Dennis Ritchie at AT & T’s Bell Laboratories  of USA in 1972. ❖ In the late seventies C began to replace the more familiar languages of that time like ALGOL, etc ❖ ANSI C standard emerged in the early 1980s. ❖ It was initially designed for programming UNIX operating system. ❖ Now the software tool as well as the C compiler is written in C. ❖ Major parts of popular operating systems like Windows, UNIX, Linux is still written in C. ❖ C is popular because it is reliable, simple and easy to use. ❖ often heard today is – “C has been already superceded by languages like C++, C# and Java. ❖ C has now become a widely used professional language for various reasons − ❑ Easy to learn ❑ Structured language ❑ It produces efficient programs ❑ It can handle low--level activities ❑ It can be compiled on a variety of computer platforms Features of C ❖ Structured programming language. break the pr...