The document provides an overview of the C programming language. It discusses that C is commonly used for embedded systems and systems programming tasks like operating systems and compilers. It was developed between 1969-1973 along with Unix. The "Hello World" example program is shown to demonstrate the basic structure of a C program with main() as the entry point. Data types, variables, and basic I/O functions like printf() and scanf() are described. Operators for arithmetic, comparison, logic, and assignment are also covered.
The document discusses various topics related to tokens, variables, data types, and operators in C programming. It defines tokens as the smallest elements identified by the compiler, such as keywords, identifiers, string literals, and operators. It describes different variable types like local variables, global variables, and static variables. It also explains various data types in C like integer, float, char, etc and their sizes and ranges. Finally, it discusses various arithmetic, relational, logical, and assignment operators in C and their precedence.
This document provides an overview of the C programming language. It discusses that C was developed in 1972 at Bell Labs and is a popular systems and applications programming language. The document then covers various C language concepts like data types, variables, operators, input/output functions, and provides examples of basic C programs and code snippets.
The document is a student submission from Dinobandhu Thokdar of Kaliacchak Government Polytechnic. It includes the student's personal details such as name, registration number, semester, and branch of study. The submission is for the subject "Basics of C".
Fundamental of C Programming Language and Basic Input/Output Functionimtiazalijoono
油
Fundamental of C Programming Language
and
Basic Input/Output Function
contents
C Development Environment
C Program Structure
Basic Data Types
Input/Output function
Common Programming Error
This document discusses program structure, data types, variables, operators, input/output functions, and debugging in C programming. It provides sample code for a program that calculates the sum of two integers entered by the user. The key steps are: 1) declaring integer variables for the two numbers and their sum, 2) using printf and scanf functions to input the numbers and output the result, and 3) returning 0 at the end of the main function. The document also covers preprocessor directives, data types, naming conventions, arithmetic and logical operators, and debugging techniques.
The document discusses the topics that will be covered in a C programming course, including:
- Introduction to C programming components like header files, preprocessor directives, main function, comments etc.
- Variable declaration and initialization, data types, operators, input/output functions like printf and scanf.
- Common statements like if-else, switch case, for, while and do-while loops.
- Functions, arrays, strings and pointers will also be covered along with evaluation methods like exams, assignments and attendance.
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.
The document provides an outline of topics for a C/C++ tutorial, including a "Hello World" program, data types, variables, operators, conditionals, loops, arrays, strings, functions, pointers, command-line arguments, data structures, and memory allocation. It gives examples and explanations of key concepts in C/C++ programming.
datypes , operators in c,variables in clanguage formatting input and out putMdAmreen
油
A data-type in C programming is a set of values and is determined to act on those values.
C provides various types of data-types which allow the programmer to select the appropriate type for the variable to set its value.
The data-type in a programming language is the collection of data with values having fixed meaning as well as characteristics. Some of them are an integer, floating point, character, etc.
Usually, programming languages specify the range values for given data-type.
C is a middle-level general purpose programming language developed in 1972. It uses characters, keywords, variables, constants, data types, expressions and operators. Variables are named locations used to store and manipulate data during execution. C supports several data types including integer, float, character and others. Operators perform actions like arithmetic, relational, logical and bitwise operations on variables and constants.
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 is a presentation on C language. Brief description on C language
Topics Covered
What is C
Header files in C
What is main function in c
Basic Structure of C
Keywords & Identifiers
Data Types & Variable Declaration in C Includes | Format Specifier | Memory Size
Input in C (printf() scanf() function)
Operators in C: Asthmatics,Increment Decrement, Relational, Logical operators
Sample Exercise
LinkedIn: https://www.linkedin.com/in/shamsulhusainansari/
GitHub: https://github.com/shamsulhusainansari
The document provides information on C language basics. It discusses that C is a system programming language useful for writing system programs like compilers, drivers, etc. It is a structured language that supports functions and modular programming. C has many built-in functions and is portable, efficient, and can access hardware. Some key aspects covered include data types in C, variables, operators, conditional statements, and input/output functions. Examples of basic C programs are also included.
This document discusses various topics related to C programming language including hardware components, algorithms, flowcharts, programming concepts like variables, data types, operators, functions etc. It provides examples of C code and explains the steps involved in program development like problem statement, analysis, design, implementation, compilation and execution. Key terms related to C like keywords, tokens, constants and conversion specifiers are also defined.
This document discusses various topics related to C programming language including hardware components, algorithms, flowcharts, programming concepts like variables, data types, operators, functions etc. It provides examples of C code to find even or odd number, a program to calculate area and perimeter of a circle. It also explains the different steps involved in program development like problem statement, analysis, design, implementation, compilation and execution.
02a fundamental c++ types, arithmetic Manzoor ALam
油
The document discusses fundamental C++ types including integers, characters, and floating-point numbers. It describes integer types like int, short, and long and their typical sizes. Character types represent single characters with examples of escape codes. Floating-point types can represent real numbers in formats like float and double. The document also covers C++ concepts such as variable definitions and declarations, arithmetic operators, assignment, and increment/decrement operators.
The document contains 40 multiple choice questions related to computer science class 12. It covers topics like variables, data types, operators, loops, functions, arrays and more. The questions test concepts like escape sequences, format specifiers, assignment operators, comments, input/output functions, and the difference between various loops in C programming language. It is a practice test to help students prepare for their computer science exam.
This document discusses tokens in the C programming language. It defines tokens as the basic building blocks of a C program, including keywords, identifiers, constants, string literals, and symbols. It provides examples of different token types and explains their meanings. It also covers identifiers, keywords, variables, constants, strings, input/output functions, and writing a basic C program.
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Chris Adamson
油
The document provides an overview of the C programming language. It begins by explaining that Objective-C extends standard ANSI C with object-oriented capabilities. It then discusses why C remains important today due to its use in libraries, operating systems, and as the base for many other popular languages. The document proceeds to cover basic C concepts like variables, data types, functions, flow control, pointers, memory allocation, and I/O parameters. It emphasizes that C provides high performance with a minimal footprint while abstracting away the CPU and memory.
The document discusses relational algebra and its basic operations. Relational algebra is a language used to query databases and manipulate tables as mathematical sets. Its core operations include selection, projection, join, union, intersection, difference, and Cartesian product. Examples are provided to illustrate each operation on sample supplier, part, and supplies tables. Exercises are also included for readers to practice applying the operations.
This document summarizes the maximum flow problem and the Ford-Fulkerson method for finding the maximum flow in a network. It defines flows, residual networks, augmenting paths, and describes how the shortest-augmenting path algorithm works by finding augmenting paths to iteratively increase the flow. It also discusses the max-flow min-cut theorem relating the maximum flow to minimum cuts in a network.
More Related Content
Similar to presentation_c_basics_1589366177_381682.pptx (20)
The document discusses the topics that will be covered in a C programming course, including:
- Introduction to C programming components like header files, preprocessor directives, main function, comments etc.
- Variable declaration and initialization, data types, operators, input/output functions like printf and scanf.
- Common statements like if-else, switch case, for, while and do-while loops.
- Functions, arrays, strings and pointers will also be covered along with evaluation methods like exams, assignments and attendance.
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.
The document provides an outline of topics for a C/C++ tutorial, including a "Hello World" program, data types, variables, operators, conditionals, loops, arrays, strings, functions, pointers, command-line arguments, data structures, and memory allocation. It gives examples and explanations of key concepts in C/C++ programming.
datypes , operators in c,variables in clanguage formatting input and out putMdAmreen
油
A data-type in C programming is a set of values and is determined to act on those values.
C provides various types of data-types which allow the programmer to select the appropriate type for the variable to set its value.
The data-type in a programming language is the collection of data with values having fixed meaning as well as characteristics. Some of them are an integer, floating point, character, etc.
Usually, programming languages specify the range values for given data-type.
C is a middle-level general purpose programming language developed in 1972. It uses characters, keywords, variables, constants, data types, expressions and operators. Variables are named locations used to store and manipulate data during execution. C supports several data types including integer, float, character and others. Operators perform actions like arithmetic, relational, logical and bitwise operations on variables and constants.
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 is a presentation on C language. Brief description on C language
Topics Covered
What is C
Header files in C
What is main function in c
Basic Structure of C
Keywords & Identifiers
Data Types & Variable Declaration in C Includes | Format Specifier | Memory Size
Input in C (printf() scanf() function)
Operators in C: Asthmatics,Increment Decrement, Relational, Logical operators
Sample Exercise
LinkedIn: https://www.linkedin.com/in/shamsulhusainansari/
GitHub: https://github.com/shamsulhusainansari
The document provides information on C language basics. It discusses that C is a system programming language useful for writing system programs like compilers, drivers, etc. It is a structured language that supports functions and modular programming. C has many built-in functions and is portable, efficient, and can access hardware. Some key aspects covered include data types in C, variables, operators, conditional statements, and input/output functions. Examples of basic C programs are also included.
This document discusses various topics related to C programming language including hardware components, algorithms, flowcharts, programming concepts like variables, data types, operators, functions etc. It provides examples of C code and explains the steps involved in program development like problem statement, analysis, design, implementation, compilation and execution. Key terms related to C like keywords, tokens, constants and conversion specifiers are also defined.
This document discusses various topics related to C programming language including hardware components, algorithms, flowcharts, programming concepts like variables, data types, operators, functions etc. It provides examples of C code to find even or odd number, a program to calculate area and perimeter of a circle. It also explains the different steps involved in program development like problem statement, analysis, design, implementation, compilation and execution.
02a fundamental c++ types, arithmetic Manzoor ALam
油
The document discusses fundamental C++ types including integers, characters, and floating-point numbers. It describes integer types like int, short, and long and their typical sizes. Character types represent single characters with examples of escape codes. Floating-point types can represent real numbers in formats like float and double. The document also covers C++ concepts such as variable definitions and declarations, arithmetic operators, assignment, and increment/decrement operators.
The document contains 40 multiple choice questions related to computer science class 12. It covers topics like variables, data types, operators, loops, functions, arrays and more. The questions test concepts like escape sequences, format specifiers, assignment operators, comments, input/output functions, and the difference between various loops in C programming language. It is a practice test to help students prepare for their computer science exam.
This document discusses tokens in the C programming language. It defines tokens as the basic building blocks of a C program, including keywords, identifiers, constants, string literals, and symbols. It provides examples of different token types and explains their meanings. It also covers identifiers, keywords, variables, constants, strings, input/output functions, and writing a basic C program.
Oh Crap, I Forgot (Or Never Learned) C! [CodeMash 2010]Chris Adamson
油
The document provides an overview of the C programming language. It begins by explaining that Objective-C extends standard ANSI C with object-oriented capabilities. It then discusses why C remains important today due to its use in libraries, operating systems, and as the base for many other popular languages. The document proceeds to cover basic C concepts like variables, data types, functions, flow control, pointers, memory allocation, and I/O parameters. It emphasizes that C provides high performance with a minimal footprint while abstracting away the CPU and memory.
The document discusses relational algebra and its basic operations. Relational algebra is a language used to query databases and manipulate tables as mathematical sets. Its core operations include selection, projection, join, union, intersection, difference, and Cartesian product. Examples are provided to illustrate each operation on sample supplier, part, and supplies tables. Exercises are also included for readers to practice applying the operations.
This document summarizes the maximum flow problem and the Ford-Fulkerson method for finding the maximum flow in a network. It defines flows, residual networks, augmenting paths, and describes how the shortest-augmenting path algorithm works by finding augmenting paths to iteratively increase the flow. It also discusses the max-flow min-cut theorem relating the maximum flow to minimum cuts in a network.
This document summarizes several graph algorithms and network flow problems. It discusses representations of graphs, common graph algorithms like breadth-first search, depth-first search, and topological sort. It also covers minimum spanning trees, single-source and all-pairs shortest paths, and maximum flow problems. For maximum flow problems, it describes the Ford-Fulkerson method using residual networks and augmenting paths to find the maximum flow in a network from a source to sink. It provides examples of how to model problems like maximum bipartite matching as a network flow problem.
The document discusses maximum flow computation and algorithms for finding the maximum flow in a flow network. It describes flow networks as directed graphs where each edge has a capacity and explains the maximum flow problem as finding the most flow that can be pushed from a source node to a sink node respecting the edge capacities. The Ford-Fulkerson algorithm and its implementation using breadth-first search (Edmonds-Karp algorithm) are presented for finding augmenting paths and incrementally increasing the flow until no more is possible.
This document discusses input and output devices for computers. It provides details on common input devices like keyboards, mice, microphones, scanners, digital cameras, and webcams. Output devices mentioned include monitors, printers, and speakers. The document also briefly discusses the BIOS and lists popular brands and price ranges for various input/output hardware. It concludes by outlining some cost-effective purchasing options for these devices aimed at home users, office secretaries, and store managers.
This document discusses computer software and operating systems. It defines application and system software, and describes different types of operating systems like single-user/single-tasking OS, single-user/multi-tasking OS, multi-user/multi-tasking OS, time sharing OS, and real-time OS. It also covers system software components like compilers, interpreters, assemblers, and device drivers. The document outlines the system development life cycle including requirement analysis, design, coding, testing, and implementation/maintenance steps.
This document provides an introduction to computer forensics. It discusses how computer usage and crime have increased, making digital evidence important to investigations. The document defines computer forensics as the preservation, identification, extraction and interpretation of computer media for legal matters. It outlines where digital evidence can be found, such as computer systems, networks, and physical storage media. Finally, it discusses challenges in computer forensics like processing large amounts of data and keeping investigation techniques up to date.
Cloud Cost Optimization for GCP, AWS, Azurevinothsk19
油
Reduce Cloud Waste across AWS, GCP, Azure and Optimize Cloud Cost with a structured approach and improve your bottomline or profitability. Decide whether you want to outsource or manage it in house.
Indian Soil Classification System in Geotechnical EngineeringRajani Vyawahare
油
This PowerPoint presentation provides a comprehensive overview of the Indian Soil Classification System, widely used in geotechnical engineering for identifying and categorizing soils based on their properties. It covers essential aspects such as particle size distribution, sieve analysis, and Atterberg consistency limits, which play a crucial role in determining soil behavior for construction and foundation design. The presentation explains the classification of soil based on particle size, including gravel, sand, silt, and clay, and details the sieve analysis experiment used to determine grain size distribution. Additionally, it explores the Atterberg consistency limits, such as the liquid limit, plastic limit, and shrinkage limit, along with a plasticity chart to assess soil plasticity and its impact on engineering applications. Furthermore, it discusses the Indian Standard Soil Classification (IS 1498:1970) and its significance in construction, along with a comparison to the Unified Soil Classification System (USCS). With detailed explanations, graphs, charts, and practical applications, this presentation serves as a valuable resource for students, civil engineers, and researchers in the field of geotechnical engineering.
Mozambique, a country with vast natural resources and immense potential, nevertheless faces several economic challenges, including high unemployment, limited access to energy, and an unstable power supply. Underdeveloped infrastructure has slowed the growth of industry and hampered peoples entrepreneurial ambitions, leaving many regions in the darkliterally and figuratively.
https://www.rofinolicuco.net/blog/how-renewable-energy-can-help-mozambique-grow-its-economy
This PPT covers the index and engineering properties of soil. It includes details on index properties, along with their methods of determination. Various important terms related to soil behavior are explained in detail. The presentation also outlines the experimental procedures for determining soil properties such as water content, specific gravity, plastic limit, and liquid limit, along with the necessary calculations and graph plotting. Additionally, it provides insights to understand the importance of these properties in geotechnical engineering applications.
The Golden Gate Bridge a structural marvel inspired by mother nature.pptxAkankshaRawat75
油
The Golden Gate Bridge is a 6 lane suspension bridge spans the Golden Gate Strait, connecting the city of San Francisco to Marin County, California.
It provides a vital transportation link between the Pacific Ocean and the San Francisco Bay.
About
Practice Head is assembled with Practice Torpedo intended for carrying out exercise firings. It is assembled with Homing Head in the forward section and oxygen flask in the rear section. Practice Head imparts positive buoyancy to the Torpedo at the end of run. The Practice Head is divided into two compartments viz. Ballast Compartment (Houses Light Device, Depth & Roll Recorder, Signal Flare Ejector, Discharge Valve, Stop Cock, Water discharge Valve, Bellow reducing Valve, Release Mechanism, Recess, Bypass Valve, Pressure Equalizer, Float, Sinking Plug etc.) which provides positive buoyancy at the end of run by discharging water (140 ltrs.) filled in the compartment and Instrument compartment (dry), houses (safety & recovery unit and its battery, combined homing and influence exploder equipment, noise maker, bollards & safety valve etc.) The recess in Ballast compartment houses the float which gets inflated at the end of run to provide floatation to the surfaced Torpedo. Several hand holes/recesses are provided on the casing/shell of Practice Head for assembly of the following components:-
a) Signal Flare Ejector Assembly
b) Depth and Roll Recorder Assembly
c) Light Device
d) Pressure equalizer
e) Drain/Discharge Valve assembly
f) Bollard Assembly
g) Holding for Floater/Balloon Assembly
h) Sinking Valve
i) Safety Valve
j) Inspection hand hole
Technical Details:
SrNo Items Specifications
1 Aluminum Alloy (AlMg5)
Casing Body Material: AlMg5
Larger Outer Diameter of the Casing: 532.4 MM
Smaller Outer Diameter of the Casing: 503.05 MM
Total Length: 1204.20 MM
Thickness: 6-8 mm
Structural Details of Casing: The casing is of uniform outer dia for a certain distance from rear side and tapered from a definite distance to the front side. (Refer T-DAP-A1828-GADWG-PH- REV 00)
Slope of the Tapered Portion: 1/8
Mass of Casing (Without components mounting, but including the ribs and collars on the body): 58.5 kg
Maximum External Test Pressure: 12 kgf/cm2
Maximum Internal Test Pressure:-
i. For Ballast Compartment: 2 kgf/cm2
ii. For Instrument Compartment: 1 kgf/cm2
Innerspace of casing assembly have 2 compartments:-
i. Ballast Compartment and
ii. Instrument Compartment
Cut outs/ recesses shall be provided for the assembly of following components.
a) Signal Flare Ejector Assembly
b) Depth and Roll Recorder Assembly
c) Light Device
d) Pressure Equalizer
e) Drain/ discharge valve assembly
2 Front Side Collar Material: AlMg5
Maximum Outer Diameter: 500 MM
Pitch Circle Diameter: 468 MM
All Dimensions as per drawing T-DAP-A1828-MDWG-C&R-REV-00
Application:
In a torpedo, the ballast components and instrument compartment play crucial roles in maintaining stability, control, and overall operational effectiveness. The ballast system primarily manages buoyancy and trim, ensuring that the torpedo maintains a stable trajectory underwater.
-Zuf辰lligurl zu
peut 辿lus silly mais les mes ishaute quils le aurais sans Les 辿tablis qui
des Louis de belle accueillis sell puss p竪re peut olds sects it's all辿tells peutall asplait suite
Il -12 ) pas cause subit lequel euros le en as d辿taill辿 de till
PILONI balo -2
ispeulit Mais anglais appareils guilt gens ils en anglais glory pile le vous pr竪s
... still que y pais vida Los play qu辿tej坦n Less via Leal su abuelos l叩stimaall) isa las
des audit elleguilt disons s'il souhait sous sirs vous lucius atoutes pouvait lets pas
il taille glacis Lieu daily qui les jeutaille pas bill Luc jean 辿cumait il taille Lacis just -Zuf辰lligurl zu
peut 辿lus silly mais les mes ishaute quils le aurais sans Les 辿tablis qui
des Louis de belle accueillis sell puss p竪re peut olds sects it's all辿tells peutall asplait suite
Il -12 ) pas cause subit lequel euros le en as d辿taill辿 de till
PILONI balo -2
ispeulit Mais anglais appareils guilt gens ils en anglais glory pile le vous pr竪s
... still que y pais vida Los play qu辿tej坦n Less via Leal su abuelos l叩stimaall) isa las
des audit elleguilt disons s'il souhait sous sirs vous lucius atoutes pouvait lets pas
il taille glacis Lieu daily qui les jeutaille pas bill Luc jean 辿cumait il taille Lacis just-Zuf辰lligurl zu
peut 辿lus silly mais les mes ishaute quils le aurais sans Les 辿tablis qui
des Louis de belle accueillis sell puss p竪re peut olds sects it's all辿tells peutall asplait suite
Il -12 ) pas cause subit lequel euros le en as d辿taill辿 de till
PILONI balo -2
ispeulit Mais anglais appareils guilt gens ils en anglais glory pile le vous pr竪s
... still que y pais vida Los play qu辿tej坦n Less via Leal su abuelos l叩stimaall) isa las
des audit elleguilt disons s'il souhait sous sirs vous lucius atoutes pouvait lets pas
il taille glacis Lieu daily qui les jeutaille pas bill Luc jean 辿cumait il taille Lacis just -Zuf辰lligurl zu
peut 辿lus silly mais les mes ishaute quils le aurais sans Les 辿tablis qui
des Louis de belle accueillis sell puss p竪re peut olds sects it's all辿tells peutall asplait suite
Il -12 ) pas cause subit lequel euros le en as d辿taill辿 de till
PILONI balo -2
ispeulit Mais anglais appareils guilt gens ils en anglais glory pile le vous pr竪s
... still que y pais vida Los play qu辿tej坦n Less via Leal su abuelos l叩stimaall) isa las
des audit elleguilt disons s'il souhait sous sirs vous lucius atoutes pouvait lets pas
il taille glacis Lieu daily qui les jeutaille pas bill Luc jean 辿cumait il taille Lacis just-Zuf辰lligurl zu
peut 辿lus silly mais les mes ishaute quils le aurais sans Les 辿tablis qui
des Louis de belle accueillis sell puss p竪re peut olds sects it's all辿tells peutall asplait suite
Il -12 ) pas cause subit lequel euros le en as d辿taill辿 de till
PILONI balo -2
ispeulit Mais anglais appareils guilt gens ils en anglais glory pile le vous pr竪s
... still que y pais vida Los play qu辿tej坦n Less via Leal su abuelos l叩stimaall) isa las
des audit elleguilt disons s'il souhait sous sirs vous lucius atoutes pouvait lets
How to Build a Speed Sensor using Arduino?CircuitDigest
油
Learn how to measure speed using IR sensors in this simple DIY project. This tutorial cover circuit diagram, Sensor calibration and speed calculations and optimized Arduino code for real time speed measurements.
2. The C Language
Currently, the most commonly-used language for
embedded systems
High-level assembly
Very portable: compilers exist for virtually every processor
Easy-to-understand compilation
Produces efficient code
Fairly concise
2
3. C History
Developed between 1969 and 1973 along with Unix
Due mostly to Dennis Ritchie
Designed for systems programming
Operating systems
Utility programs
Compilers
3
4. Hello World in C
#include <stdio.h>
int main()
{
printf(Hello, world!n);
}
4
5. Hello World in C
#include <stdio.h>
int main()
{
printf(Hello, world!n);
}
Program mostly a
collection of functions
main function special:
the entry point
int qualifier indicates
function returns an
integer
I/O performed by a library
function: not included in
the language
5
6. Pieces of C
Types and Variables (LO2)
Definitions of data in memory
Expressions (LO2)
Arithmetic, logical, and assignment operators in an infix
notation
Statements (LO3)
Sequences of conditional, iteration, and branching
instructions
Functions (LO4)
Groups of statements and variables invoked recursively
6
7. Name Description Size* Range*
char Character or small integer 1 byte signed: -128 to 127
unsigned: 0 to 255
short int
(short)
Short integer 2 bytes signed: -32768 to 32767
unsigned: 0 to 65535
int Integer 4 bytes signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
long int
(long)
Long integer 4 bytes signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
float Floating point number 4 bytes 3.4e +/- 38 (7 digits)
double Double precision floating
point number
8 bytes 1.7e +/- 308 (15 digits)
long double Long double precision
floating point number
8 bytes 1.7e +/- 308 (15 digits)
Data types
7
8. Local variable
Local variables are declared within the body of a function, and can
only be used within that function.
Static variable
Another class of local variable is the static type. It is specified by the
keyword static in the variable declaration.
The most striking difference from a non-static local variable is, a
static variable is not destroyed on exit from the function.
Global variable
A global variable declaration looks normal, but is located outside any
of the program's functions. So it is accessible to all functions.
Variable types
8
9. Variables
A variable is a name that represents one or more memory
locations used to hold program data
A variable may be thought of as a container that can hold
data used in a program
int myVariable;
myVariable = 5;
5
9
10. An example
int global = 10; //global variable
int func (int x)
{
static int stat_var; //static local variable
int temp; //(normal) local variable
int name[50]; //(normal) local variable
}
10
12. char first_letter;
int warp_factor;
Variable declarations consist of a unique identifier (name)
float length;
41
Variables
5.74532370373175
10-14
0
15 Data Memory (RAM)
A
12
13. char first_letter;
float length;
int warp_factor; 41
Variables
5.74532370373175
10-44
0
15 Data Memory (RAM)
A
and a data type
Determines size and how
values are interpreted
13
14. Identifiers
Names given to program variables
Valid characters in identifiers:
Case sensitive!
Only first 31 characters significant
I d e n t i f i e r
First Character
_ (underscore)
A to Z
a to z
Remaining Characters
_ (underscore)
A to Z
a to z
0 to 9
14
15. How to Declare a Variable?
A variable must be declared before it can be used
The compiler needs to know how much space to allocate and
how the values should be handled
Syntax
type identifier1, identifier2,,identifiern;
Examples
int x, y, z;
float warpFactor;
char text_buffer;
unsigned index;
Variables
15
16. Syntax
How to Declare a Variable?
Variables may be declared in a few ways:
type identifier;
type identifier = InitialValue;
type identifier1, identifier2, identifier3;
type identifier1 = Value1, identifier2 = Value2;
One declaration on a line
One declaration on a line with an initial value
Multiple declarations of the same type on a line
Multiple declarations of the same type on a line with initial values
Variables
16
17. Examples
How to Declare a Variable
int x;
int y = 12;
int a, b, c;
long int myVar = 0x12345678;
long z;
char first = 'a', second, third = 'c';
float big_number = 6.02e+23;
Variables
17
18. A Simple C Program
#include <stdio.h>
int main(void)
{
float radius, area, PI;
//Calculate area of circle
radius = 12.0;
PI = 3.1416;
area = PI * radius * radius;
printf("Area = %f", area);
}
Header File
Function
Variable Declarations
Comment
Preprocessor
Directives
18
19. Variables and Data Types
Variable
Declarations
Data
Types
Variables
in use
#include <stdio.h>
int main(void)
{
float radius, area, PI;
//Calculate area of circle
PI = 3.1416;
radius = 12.0;
area = PI * radius * radius;
printf("Area = %f", area);
}
A Simple C Program
19
20. printf()
The printf() function can be instructed to print
integers, floats and string properly.
The general syntax is
printf( format, variables);
An example
int stud_id = 5200;
char name[20] = Mike; // array discussed in LO4
printf(%s s ID is %d n, name, stud_id);
20
21. Format Identifiers
%d decimal integers
%x hex integer
%c character
%f float number
%lf double number
%s string
%p pointer
%e decimal exponent
How to specify display space for a variable?
printf(The student id is %5d n, stud_id);
The value of stud_id will occupy 5 characters space in the print-out.
printf()
21
22. Why n
It introduces a new line on the terminal screen.
a alert (bell) character backslash
b backspace ? question mark
f formfeed single quote
n newline double quote
r carriage return 000 octal number
t horizontal tab xhh hexadecimal number
v vertical tab
escape sequence
22
24. scanf()
Description:
The C library function
int scanf(const char *format, ...) reads formatted input from
keyboard. The function returns how many values where read. If scanf
returns a 0 it means nothing was read.
Declaration:
Following is the declaration for scanf() function.
int scanf(const char *format, ...)
Example:
int a, result;
result = scanf("%d", &a);
24
25. Example: The following example shows the usage of scanf() function to read strings.
Note: in scanf, we do not use & with array names
#include <stdio.h>
int main()
{
char str1[20], str2[30];
printf("Enter name: ");
scanf("%s", str1);
printf("Enter your website name: ");
scanf("%s", str2);
printf("Entered Name: %sn", str1);
printf("Entered Website:%s", str2);
}
scanf()
Enter name: admin
Enter your website name: www.tutorialspoint.com
Entered Name: admin
Entered Website: www.tutorialspoint.com
25
26. What happens in this program? An integer called pin is defined. A prompt to enter in a number is then printed with
the first printf statement. The scanf routine, which accepts the response, has a control string and an address list.
In the control string, the format specifier %d shows what data type is expected.
The &pin argument specifies the memory location of the variable the input will be placed in. After the scanf routine
completes, the variable pin will be initialized with the input integer. This is confirmed with the second printf
statement. The & character has a very special meaning in C. It is the address operator.
Is a function in C which allows the
programmer to accept input from a
keyboard. The following program
illustrates the use of this function.
scanf()
#include <stdio.h>
main() {
int pin;
printf("Please type in your
PINn");
scanf("%d",&pin);
printf("Your access code is
%dn",pin);
}
26
27. Negative
-(unary)
Subtraction
-
Positive
+(unary)
Modulo
%
Addition
+
NOTE - An int divided by an int returns an int:
10/3 = 3
Use modulo to get the remainder:
10%3 = 1
Multiplication
*
Division
/
Operator Result
Operation Example
-x
x - y
+x
x % y
x + y
x * y
x / y
Negative value of x
Difference of x and y
Value of x
Remainder of x divided by y
Sum of x and y
Product of x and y
Quotient of x and y
Arithmetic Operations
27
29. Operator Result (FALSE = 0, TRUE 0)
Operation Example
Equal to
==
Not equal to
!=
Greater than
>
Greater than
or equal to
>=
Less than
<
Less than or
equal to
<=
x == y
x != y
x > y
x >= y
x < y
x <= y
True if x equal to y, else false
True if x not equal to y, else
false
True if x greater than y, else
false
True if x greater than or equal
to y, else false
True if x less than y, else false
True if x less than or equal to y,
else false
Relational Operations
29
30. Increment and Decrement Operators
awkward easy easiest
x = x+1; x += 1 x++
x = x-1; x -= 1 x--
30
31. Example
Arithmetic operators
int i = 10;
int j = 15;
int add = i + j; //25
int diff = j i; //5
int product = i * j; // 150
int quotient = j / i; // 1
int residual = j % i; // 5
i++; //Increase by 1
i--; //Decrease by 1
31
32. Comparing them
int i = 10;
int j = 15;
float k = 15.0;
j / i = ?
j % i = ?
k / i = ?
k % i = ?
The Answer
j / i = 1;
j % i = 5;
k / i = 1.5;
k % i It is illegal.
Note: For %, the operands
can only be integers.
Example
32
33. Logical Operations
What is true and false in C
In C, there is no specific data type to represent true and
false. C uses value 0 to represent false, and uses non-
zero value to stand for true.
Logical Operators
A && B => A and B
A || B => A or B
A == B => Is A equal to B?
A != B => Is A not equal to B?
33
34. A > B => Is A greater than B?
A >= B => Is A greater than or equal to B?
A < B => Is A less than B?
A <= B => Is A less than or equal to B?
Dont be confused
&& and || have different meanings from & and |.
& and | are bitwise operators.
Logical Operations
34
35. No operator for exponent in C
In C, there is no operator which means raise to the power. The
symbol ^ means Bitwise Exclusive Or or XOR which gives a 1
if the two bits are different and zero otherwise.
Assume char A = 60 and char B = 13 in binary format, they will be
as follows
A = 0011 1100
B = 0000 1101
A&B = 0000 1100 Bitwise AND
A|B = 0011 1101 Bitwise OR
A^B = 0011 0001 Bitwise XOR
If you need to find a power, you should use multiplication *
For example, x*x*x is the same as 3
35
36. Precedence and Associativity of C Operators
Symbol Type of Operation Associativity
[ ] ( ) . > 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
? : Conditional-expression Right to left
= *= /= %=
+= = <<= >>= &=
^= |=
Simple and compound
assignment
Right to left
, Sequential evaluation Left to right
OPERATOR PRECEDENCE
36
37. Some practices
Compute the value of the following logical expressions?
int i = 10; int j = 15; int k = 15; int m = 0;
if( i < j && j < k) =>
if( i != j || k < j) =>
if( j<= k || i > k) =>
if( j == k && m) =>
if(i) =>
if(m || j && i ) =>
37
38. int i = 10; int j = 15; int k = 15; int m = 0;
if( i < j && j < k) => false
if( i != j || k < j) => true
if( j<= k || i > k) => true
if( j == k && m) => false
if(i) => true
if(m || j && i ) => true
Answers
38