0% found this document useful (0 votes)
64 views13 pages

Data Types

The document discusses basic concepts in C programming including program structure with main(), comments, data types like int and float, variables, operators like arithmetic, relational, and logical, and input/output functions like printf() and scanf(). It provides examples of declaring variables, using operators, and taking user input and printing output in a simple C program.

Uploaded by

Ishaan
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)
64 views13 pages

Data Types

The document discusses basic concepts in C programming including program structure with main(), comments, data types like int and float, variables, operators like arithmetic, relational, and logical, and input/output functions like printf() and scanf(). It provides examples of declaring variables, using operators, and taking user input and printing output in a simple C program.

Uploaded by

Ishaan
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/ 13

C Programming

Program Structure
#include <stdio.h>

int main() {
/* my first program in C */
printf("Hello, World! \n");

return 0;
}
• Tokens in C
printf("Hello, World! \n");

• Semicolons
In a C program, the semicolon is a statement terminator.
printf("Hello, World! \n");

• Comments
/* my first program in C */
// single line comment

• Identifiers
A C identifier is a name used to identify a variable, function, or
any other user-defined item.
Mohd zara abc move_name a_123 myname50 _temp j a23b9
retVal
• Keywords
auto else long switch
break enum register typedef
case extern return union
char float short unsigne
d
const for signed void
continue goto sizeof volatile
default if static while
do int struct _Packed
double
• Whitespace in C
int age;
fruit = apples + oranges; // get the total fruit
Data Types

• The type of a variable determines how much


space it occupies in storage and how the bit
pattern stored is interpreted.

• Basic Types
• Enumerated types
• The type void
• Derived types
• Integer Types
Type Storage Value range
size
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 -32,768 to 32,767 or -2,147,483,648 to
bytes 2,147,483,647
unsigned int 2 or 4 0 to 65,535 or 0 to 4,294,967,295
bytes
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
• Floating-Point Types

Type Storage size Value range Precision


float 4 byte 1.2E-38 to 6 decimal
3.4E+38 places
double 8 byte 2.3E-308 to 15 decimal
1.7E+308 places
long double 10 byte 3.4E-4932 to 19 decimal
1.1E+4932 places
Variables

• A variable is a name given to a storage area, so


that our programs can manipulate. 
int i, j, k;
char c, ch;
float f, salary;
double d;

int d = 3, f = 5; // definition and initializing d


and f. char x = 'x';
• Arithmetic Operators
Operators

+ - / * % ++ --
• Relational Operators
== != > < >= <=
• Logical Operators
&& || !
• Bitwise Operators
& | ^ ~ << >>
55 << 2 25>>3
65 & 23
25 | 10
Operators
• Assignment Operators
= += -+ *= /= %= <<= >>= &= |= ^=
• Misc Operators

Operator Example
sizeof() sizeof(a), where a is integer, will return 4.
& &a; returns the actual address of the
variable.
* *a;
?: If Condition is true ? then value X :
otherwise value Y
printf() and scanf()
#include <stdio.h>
int main()
{
int n;
printf("Enter an integer: ");
scanf("%d",&n);
printf("Number = %d",n);
return 0;
}
• If (a>b)
• Print
• Else
• Print
• If(a>b)?a:b

You might also like