0% found this document useful (0 votes)
31 views

Chapter 1 Notes

Variable is the name of a memory location that stores data. Variables follow certain rules: a) they are case sensitive, b) the first character must be a letter or underscore, and c) they cannot contain commas or blank spaces. The document then provides examples of C code demonstrating variables, data types, constants, keywords, program structure, comments, input/output using printf and scanf, and compilation.

Uploaded by

ash.qureshi993
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Chapter 1 Notes

Variable is the name of a memory location that stores data. Variables follow certain rules: a) they are case sensitive, b) the first character must be a letter or underscore, and c) they cannot contain commas or blank spaces. The document then provides examples of C code demonstrating variables, data types, constants, keywords, program structure, comments, input/output using printf and scanf, and compilation.

Uploaded by

ash.qureshi993
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Variables

Variable is the name of a


memory location which stores
some data.

Memory

a b
25 S
Variables
R u le s

a. Variables are case sensitive

b. 1st character is alphabet or '_'

c. no comma/blank s pace

d. No other symbol other than


'_'
C Language Tutorial
(Basic to Advanced)

Variables, Data Types + Input/Output


(Chapter 1)

1. First Program
#include<stdio.h>
2. Variables & Data Types + Constants & Keywords

int main()
{ printf("HeloWorld");
return 0;
}

#include<stdio.h>

int main() {
int number;
int age;
int price;
return 0;
}
#include<stdio.h>

//This program
prints Hello World
int main() {
printf("Hello
World");
return 0;
}
#include<stdio.h>

int main() {
int age = 22;
float pi = 3.14;
char percentage =
'%'; return 0;
}
#include<stdio.h>

int main() {
int age = 22;
float pi = 3.14;
char percentage =
'%';

printf("age is %d", age);


printf("age is %f", pi);
printf("age is %c",
percentage);

return 0;
}
#include<stdio.h>

int main() { int a, b;

printf("enter a \n");
scanf("%d", &a);

printf("enter b \n");
scanf("%d", &b);

printf("sum of a & b is : %d \n",

a+b);

return 0;
}
6. Practice Qs 1 (Area of Square)

#include<stdio.h>
//area of square int main()
{
int side; scanf("% , &side);
printf("%d", side * side);
return 0;
}
7. Practice Qs 2 (Area of Circle)

#include<stdio.h>

//area of square int


main() {
float radius;
scanf("%f", &radius);
printf("%f", 3.14 * radius *
radius);
return 0;
}
Variables
Data Ty pes
Constants
Val u e s that don't
change(fixed)

Types

Integer Char acter


Constants Real
Constants Con st an ts
1, 2, 3, ' a ', ' b ',
0 ' A ', '#',
1.0, 2.0,
, -1, -2 '&'
3.14, -
24
Ke yw or d s
Reserved words that have
special meaning to the compiler

32 Keyword s in C
Ke yw or d s
auto double int struct

break else long switch

case enum register typedef

char extern return union

continue for signed void

do if static while

default goto sizeof volatile

const float short unsigned


Program Structure

# incl u de < s t dio . h >

in t main () {
prin t f (" Hello World ");
re t u rn 0 ;
}
Comments
Lines that are not part of
program

Single M u ltiple
Line Line

/*
/
*
/
/
Outpu
t
printf(" Hello Wo r ld
");

new line
printf(" kuch bhi \
n ");
Outpu
t
CASES
1. integers
pr intf(" age is % d " , age);

2. real numbers
printf(" value of pi is % f ", pi);

3. characters
printf(" star looks like this % c ",
star);
Inpu
t
scanf(" % d ",
&age);
Compilation
A computer program that translates C
code into machine code

a.exe (windows)
Hello.c C Compiler
a.out (linux &
mac)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy