0% found this document useful (0 votes)
14 views79 pages

Unit 1

The document outlines the fundamentals of programming in C, covering topics such as computer systems, software types, programming languages, and the process of creating and running C programs. It details the structure of C programs, including tokens, identifiers, keywords, data types, variables, constants, and operators. Additionally, it provides examples and rules for writing C code, emphasizing the importance of understanding syntax and data management.

Uploaded by

MonikaBansal
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)
14 views79 pages

Unit 1

The document outlines the fundamentals of programming in C, covering topics such as computer systems, software types, programming languages, and the process of creating and running C programs. It details the structure of C programs, including tokens, identifiers, keywords, data types, variables, constants, and operators. Additionally, it provides examples and rules for writing C code, emphasizing the importance of understanding syntax and data management.

Uploaded by

MonikaBansal
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/ 79

Unit-I

Programming in C
Course Objectives
Course Outcomes
COs-POs
Syllabus-Unit 1
Syllabus-Unit 2
Syllabus-Unit 3
Syllabus-Unit 4
Books
Books
Computer systems
Computer hardware is the collection of physical
elements that comprise a computer system.

A computer system consists of


hardware and software.

.
Computer systems

Computer software is a collection of computer programs and related data that


provides the instructions for a computer what to do and how to do it. Software refers
to one or more computer programs and data held in the storage of the computer for
some purpose.

.
System Software
System Software: System software is responsible for
managing a variety of independent hardware
components, so that they can work together.
• Device drivers
• Operating systems
• Servers
• Utilities
• Window systems

.
System Software

System Development Software: Development Software


usually provides tools to assist a programmer in writing
computer programs, and software using different
programming languages in a more convenient way.
• Compilers
• Debuggers
• Interpreters
• Linkers
• Text editors

.
Application Software
Application Software: Application software is developed to aid in any task that
benefits from computation. It is a broad category, and encompasses Software of
many kinds, including the internet browser being used to display this page. This
category includes:
• Business software
• Computer aided design
• Databases
• Decision making software
• Educational software
• Image editing

.
COMPUTER LANGUAGES

1. Low Level Languages.


2. High Level Languages.

Low Level Languages


Low level computer languages are machine codes or close to it. Computer cannot
understand instructions given in high level languages or in English. It can only
understand and execute instructions given in the form of machine language i.e.
language of 0 and 1. There are two types of low level languages:

Machine Language.
Assembly Language

.
COMPUTER LANGUAGES

Assembly Language

It was developed to overcome some of the many inconveniences of machine language.


This is another low level but a very important language in which operation codes and
operands are given in the form of alphanumeric symbols instead of 0‟s and l‟s. These
alphanumeric symbols will be known as mnemonic codes and can have maximum up to
5 letter combination e.g. ADD for addition, SUB for subtraction, START,LABEL etc.
Because of this feature it is also known as „Symbolic Programming Language‟. This
language is also very difficult and needs a lot of practice to master it because very
small.

.
COMPUTER LANGUAGES

High Level Languages


High level computer languages give formats close to English language and the purpose
of developing high level languages is to enable people to write programs easily and in
their own native language environment (English). High-level languages are basically
symbolic languages that use English words and/or mathematical symbols rather than
mnemonic codes. Each instruction in the high-level language is translated into many
machine language instructions thus showing one-to-many translation.

.
Creating and Running Programs

.
Source Code → (Preprocessor) → Processed Source Code
Processed Source Code → (Compiler) → Object File
Object File → (Linker) → Executable File
Executable File → (Loader) → Running Program
Creating and Running Programs

There are four steps in this process.


1. Writing and editing the program using Text editor (source code).
2. Compile the program using any C compiler.(.)
3. Linking the program with the required library modules(object file)
4. Executing the program. (.Exe file)

.
Creating and Running Programs

Creating and Editing a C Program in C Programming Language compiler:


Writing or creating and editing source program is a first step in c language. Source
code is written in c programming language according to the type of problem or
requirement, in any text editor.
Saving C Program in C Programming Language: Source code is saved on the
secondary storage. Source code is saved as text file. The extension of file must be
".c". Example the file name is "learn c programming language.c

.
Creating and Running Programs

Compiling C program in C Programming Language: Computer does not understand c


programming language. It understands only 0 and 1 means machine language. So c
programming language code is converted into machine language.The process of
converting source code in to machine code is called compiling.Compiler is a program
that compiles source code. Compiler also detects errors in source program. If
compiling is successful source program is converted into object program. Object
program is saved on disk. The extension of file is ".obj"
Linking in C programming Language: There are many built in functions available in c
programming language. These functions are also called library functions. These
functions are stored in different header files.

.
Creating and Running Programs

Loading program: The process of transferring a program from secondary storage to


main memory for execution is called loading a program. A program called loader does
loading.
Executing program: Execution is the last step. In this step program starts execution.
Its instructions start working and output of the program display on the
screen.

.
C Program

1. #include <stdio.h>
2. void main(){
3. printf("Hello C Language");
4. }
#include <stdio.h> includes the standard input output library functions. The printf()
function is defined in stdio.h .

.
C Program

void main() The main() function is the entry point of every program in c language. The
void keyword specifies that it returns no value.
printf() The printf() function is used to print data on the console.
getch() The getch() function asks for a single character. Until you press any key, it
blocks the screen.

.
C TOKENS
In C programming, a token is the smallest unit of meaningful code that the compiler recognizes and
processes.

It represents a series or sequence of characters that cannot be decomposed further.

Tokens are the building blocks of a C program.

C has six types of tokens.

1: Identifiers

2: Keywords

3: Constants

4: Strings

5: Special Symbols

6: Operators
.
Types of Token in C

.
Types of Token in C

.
Example:
#include <stdio.h> // Token: Preprocessor directive
int main() { // Token: Keyword (int), Identifier (main), Punctuation (())
int x = 5; // Token: Keyword (int), Identifier (x), Operator (=), Constant (5), Punctuation (;)
printf("Value: %d", x); // Token: Identifier (printf), String literal ("Value: %d"), Operator (,), Identifier (x), Punctuation (;)
return 0; // Token: Keyword (return), Constant (0), Punctuation (;)
}

.
Identifiers:
Identifiers refer to the names of variables, constants, functions and arrays. These are user-defined names is called
Identifiers. These identifier are defined against a set of rules.

Rules for an Identifier

1. An Identifier can only have alphanumeric characters( a-z , A-Z , 0-9 ) and underscore( _ ).

2. The first character of an identifier can only contain alphabet( a-z , A-Z ) or underscore ( _ ).

3. Identifiers are also case sensitive in C. For example name and Name are two different identifier in C.

4. Keywords are not allowed to be used as Identifiers.

5. No special characters, such as semicolon, period, whitespaces, slash or comma are

permitted to be used in or as Identifier.


.
6. C‟ compiler recognizes only the first 31 characters of an identifiers.
Identifiers

5. No special characters, such as semicolon, period, whitespaces, slash or comma are

permitted to be used in or as Identifier.

6. C‟ compiler recognizes only the first 31 characters of an identifiers

Ex : Valid Invalid

STDNAME return

SUB $stay

TOT_MARKS 1RECORD

._TEMP STD NAME.

Y2K
Keywords

A keyword is a reserved word. All keywords have fixed meaning that means we
cannot change. Keywords serve as basic building blocks for program statements. All
keywords must be written in lowercase.
Example auto, break, case, char, const, continue, default etc.

Note: Keywords we cannot use it as a variable name, constant name etc.

.
Data Types/Types

Data Types – is a collection or grouping of data values, usually specified by a set of


possible values, a set of allowed operations on these values, and/or a representation
of these values as machine types.

To store data the program must reserve space which is done using datatype. A datatype is a
keyword/predefined instruction used for allocating memory for data. A data type specifies the type of data
that a variable can store such as integer, floating, character etc. It used for declaring/defining variables or
functions of different types before to use in a program. There are 3 types of data types in C language.

1. Basic or Primary Data Type

2. Derived Data Type

.
3. Enumeration Data
Data Types/Types
#include <stdio.h>
Basic or Primary Data Type- int, char, float, double, void int main() {
Derived Data Type- array, pointer, structure, union int number1, number2, sum;

Enumeration Data -Type enum printf("Enter two integers: ");


scanf("%d %d", &number1,
&number2);

// calculate the sum


sum = number1 + number2;

printf("%d + %d = %d", number1,


number2, sum);
. return 0;
}
Primary Data Types

.
Primary Data Types
Datatype size in bytes

char = 1
unsigned char = 1
int = 4
long int = 8
short int = 2
float = 4
double = 8
long double = 16

.
Enumerated Data Type

enum week{Mon, Tue, Wed};


enum week day;
Variables

A variable is a name of memory location. It is used to store data. Variables are


changeable, we can change value of a variable during execution of a program. . It can
be reused many times.
Note: Variable are nothing but identifiers.
Rules to write variable names:
1. A variable name contains maximum of 30 characters. However, the length should
not be normally more than any combination of 8 alphabets, digits, and underscores.
2.
. A variable name includes alphabets and numbers, but it must start
with an alphabet.
3. It cannot accept any special characters, blank spaces except under score( _ ).
Variables

4. It should not be a reserved word.


Ex : i ,rank1, MAX, min, Student_name.
StudentName , class_mark
Declaration of Variables : A variable can be used to store a value of any data type.
The declaration of variables must be done before they are used in the program. The
general format for declaring a variable.
Syntax : data_type variable-1,variable-2,------, variable-n;
.Variables are separated by commas and declaration statement ends with a
semicolon. Ex : int x,y,z;
float a,b; char m,n;
Variables

Assigning values to variables : values can be assigned to variables using the


assignment
operator (=). The general format statement is :
Syntax : variable = constant;
Ex : x=100;
a= 12.25;
m=’f’;
.
char m=’f’;
Constants

Constants refer to fixed values that do not change during the execution of a program.
Note: constants are also called literals.

.
TYPES OF C CONSTANT

1. Integer constants
2. Real or Floating point constants
3. Character constants
4. String constants
5. Backslash character constants

.
TYPES OF C CONSTANT
Integer constants:
An integer constant is a numeric constant (associated with number) without any
fractional or exponential part. There are three types of integer constants in C
programming:
decimal constant(base 10)
octal constant(base 8)
hexadecimal constant(base 16)
For
. example:Decimal constants: 0, -9, 22 etc
 Octal constants: 021, 077, 033 etc
 Hexadecimal constants: 0x7f, 0x2a, 0x521 etc
TYPES OF C CONSTANT
Floating point/Real constants:
A floating point constant is a numeric constant that has either a fractional form or an
exponent form. For example: -2.0
0.0000234
-0.22E-5

.
TYPES OF C CONSTANT
Character Constant:
Single Character Constant : A character constant is either a single alphabet, a single
digit, a
single special symbol enclosed within single inverted commas.
a) it is value represent in „ „ (single quote).
b) The maximam length of a character constant can be 1 character.
EX : VALID INVALID
. ‘a’ “12”
Escape characters or backslash
characters:
a) \n newline j) \? Question mark (?)

b) \r carriage return k) \\ backslash (\)

c) \t tab
d) \v vertical tab
e) \b backspace
f) \f form feed (page feed)
g) \a alert (beep)
.
h) \‟ single quote(„)
i) \” double quote(“)
Two ways to define constant in C
1. const keyword

2. #define preprocessor
C const keyword

The const keyword is used to define constant in C programming.

const float PI=3.14;

Now, the value of PI variable can't be changed.

1. #include <stdio.h>

2. #include <conio.h>

3. void main(){
.
4. const float PI=3.14;

5. clrscr();

6. printf("The value of PI is: %f",PI);


Two ways to define constant in C
7. getch();

8. }

Output:

The value of PI is: 3.140000

2) C #define preprocessor

The #define preprocessor is also used to define constant.

C#define

The #define preprocessor directive is used to define constant or micro substitution. It can use any

basic. data type.


Two ways to define constant in C
#include <stdio.h>

1. #define PI 3.14

2. main() {

3. printf("%f",PI);

4. }

Output:

3.140000

.
OPERATORS AND EXPRESSIONS:
Operators : An operator is a Symbol that performs an operation. An operators acts some variables are
called operands to get the desired result.Ex : a+b; Where a,b are operands and + is the operator.Types
of Operator :

1) Arithmetic Operators.

2) Relational Operators.

3) Logical Operators.

4) Assignment Operators.

5). Unary Operators.

6) Conditional Operators.
.
7) Special Operators.

8) Bitwise Operators.

9) Shift Operators.
Arithmetic Operators
An arithmetic operator performs mathematical operations such as addition, subtraction and

multiplication on numerical values (constants and variables).


#include <stdio.h>
void main()
{int a = 9,b = 4, c;
c = a+b;
printf("a+b = %d \n",c);
c = a-b;
printf("a-b = %d \n",c);
c = a*b;
printf("a*b = %d \n",c);
c=a/b;
.
printf("a/b = %d \n",c);
c=a%b;
printf("Remainder when a divided by b = %d \n",c);
}
Relational Operators
A relational operator checks the relationship between two operands. If the relation is true, it returns 1; if the
relation is false, it returns value 0.

.
Relational Operators
#include <stdio.h>
Output
int main() 5 == 5 = 1
{int a = 5, b = 5, c = 10; 5 == 10 = 0
printf("%d == %d = %d \n", a, b, a == b); // true 5>5=0
printf("%d == %d = %d \n", a, c, a == c); // false 5 > 10 = 0
printf("%d > %d = %d \n", a, b, a > b); //false 5<5=0
printf("%d > %d = %d \n", a, c, a > c); //false 5 < 10 = 1
printf("%d < %d = %d \n", a, b, a < b); //false
5 != 5 = 0
printf("%d < %d = %d \n", a, c, a < c); //true
printf("%d != %d = %d \n", a, b, a != b); //false 5 != 10 = 1
printf("%d != %d = %d \n", a, c, a != c); //true 5 >= 5 = 1
.
printf("%d >= %d = %d \n", a, b, a >= b); //true 5 >= 10 = 0
printf("%d >= %d = %d \n", a, c, a >= c); //false 5 <= 5 = 1
printf("%d <= %d = %d \n", a, b, a <= b); //true 5 <= 10 = 1
printf("%d <= %d = %d \n", a, c, a <= c); //true
Logical Operators.
These operators are used to combine the results of two or more conditions. An
expression containing logical operator returns either 0 or 1 depending upon whether
expression results true or false. Logical operators are commonly used in decision making
in C programming

.
Logical Operators.

.
Logical Operators.
#include <stdio.h>
int main() Output
{
int a = 5, b = 5, c = 10, result; (a == b) && (c > b) equals to 1
result = (a == b) && (c > b); (a == b) && (c < b) equals to 0
printf("(a == b) && (c > b) equals to %d \n", result); (a == b) || (c < b) equals to 1
result = (a == b) && (c < b);
printf("(a == b) && (c < b) equals to %d \n", result); (a != b) || (c < b) equals to 0
result = (a == b) || (c < b); !(a != b) equals to 1
printf("(a == b) || (c < b) equals to %d \n", result);
result = (a != b) || (c < b);
!(a == b) equals to 0
printf("(a != b) || (c < b) equals to %d \n", result);
result = !(a != b);
printf("!(a == b) equals to %d \n", result);
result .= !(a == b);
printf("!(a == b) equals to %d \n", result);
return 0;
}
Assignment Operators
Assignment operators are used to assign a value (or) an expression (or) a value of a variable to another
variable.

Syntax : variable name=expression (or) value (or) variable


Ex : x=10;
y=a+b;
z=p

.
Assignment Operators
#include <stdio.h>
int main() Output
{
int a = 5, c; c=5
c = a; c = 10
printf("c = %d \n", c); c=5
c += a; // c = c+a
printf("c = %d \n", c); c = 25
c -= a; // c = c-a c=5
printf("c = %d \n", c);
c *= a; // c = c*a
c=0
printf("c = %d \n", c);
c /= a; // c = c/a
printf("c = %d \n", c);
c %= a;. // c = c%a
printf("c = %d \n", c);
return 0;
}
Increment and Decrement Operators /Unary
Operators:
Unary operators are having higher priority than the other #include <stdio.h>
operators. Unary operators, meaning they only operate
int main()
on a single operand.
{
int a = 10, b = 100;
float c = 10.5, d = 100.5;
printf("++a = %d \n", ++a);
printf("--b = %d \n", --b);
printf("++c = %f \n", ++c);
printf("--d = %f \n", --d);
return 0;
}
Output
++a = 11
. --b = 99
++c = 11.500000
++d = 99.500000
Increment and Decrement Operators /Unary
Operators:
#include<stdio.h> #include<stdio.h>
void main() {
#include<conio.h>
int i = 1;
printf("%d %d %d", i, ++i, i++);
void main() {
} int i = 0, j = 0;
Output : 3 3 1 j = i++ + ++i;
printf("%d\n", i);
printf("%d\n", j);
}
Output :
2
2

.
Conditional Operator/ Ternary operator:

conditional operator checks the condition #include <stdio.h>


and executes the statement depending of int main() {
the condition. int a = 10, b = 20;
A conditional operator is a ternary // Find the maximum of two numbers using the conditional
operator, that is, it works on 3 operands. operator
Conditional operator consist of two int max = (a > b) ? a : b;
symbols. printf("The larger number is: %d\n", max);
1 : question mark (?). return 0;
2 : colon ( : ) }
Syntax : condition ? exp1 : exp2; Output
The larger number is: 20

.
Bitwise Operators:

Bitwise operators are used to manipulate the data


at bit level. It operates on integers only. It
may not be applied to float.In arithmetic-logic unit
(which is within the CPU), mathematical
operations like: addition, subtraction, multiplication
and division are done in bit-level which
makes processing faster and saves power. To
perform bit-level operations in C programming,
bitwise operators are used.

.
Bitwise Operators:

Bitwise operators are used to manipulate the data


at bit level. It operates on integers only. It
may not be applied to float.In arithmetic-logic unit
(which is within the CPU), mathematical
operations like: addition, subtraction, multiplication
and division are done in bit-level which
makes processing faster and saves power. To
perform bit-level operations in C programming,
bitwise operators are used.

.
Bitwise AND operator &

Let us suppose the bitwise AND operation of two Example #1: Bitwise AND
integers 12 and 25.
12 = 00001100 (In Binary)
#include <stdio.h>
25 = 00011001 (In Binary) int main()
{
Bit Operation of 12 and 25
00001100 int a = 12, b = 25;
& 00011001 printf("Output = %d", a&b);
________
00001000 = 8 (In decimal)
return 0;
}
Output
Output =8
.
Bitwise OR operator |

The result of bitwise XOR operator is 1 if the #include <stdio.h>


corresponding bits of two operands are opposite. It
is denoted by ^.
int main()
12 = 00001100 (In Binary) {
25 = 00011001 (In Binary) int a = 12, b = 25;
Bitwise XOR Operation of 12 and 25
00001100 printf("Output = %d", a^b);
| 00011001 return 0;
________
00010101 = 21 (In decimal)
}
Output
Output = 21

.
Bitwise XOR (exclusive OR) operator ^

The output of bitwise OR is 1 if at least one #include <stdio.h>


corresponding bit of two operands is 1. In C
Programming, bitwise OR operator is denoted by |.
int main()
12 = 00001100 (In Binary) {
25 = 00011001 (In Binary) int a = 12, b = 25;
Bitwise OR Operation of 12 and 25
00001100 printf("Output = %d", a|b);
| 00011001 return 0;
________
00011101 = 29 (In decimal)
}
Output
Output =29

.
Bitwise complement operator ~

Bitwise compliment operator is an unary operator


(works on only one operand). It changes 1 to 0
and 0 to 1. It is denoted by ~.
35 = 00100011 (In Binary)
Bitwise complement Operation of 35
~ 00100011
________
11011100 = 220 (In decimal)
2's Complement
Two's complement is an operation on binary
numbers. The 2's complement of a number is equal
to the complement of that number plus 1. For
example:

.
Bitwise complement operator ~

#include <stdio.h>
int main()
{
printf("complement = %d\n",~35);
printf("complement = %d\n",~-12);
return 0;
}
Output
Complement = -36
Complement = 11

.
Bitwise shift operators

There are two Bitwise shift operators in C


programming: #include <stdio.h>
1.  Right shift operator
2.  Left shift operator. int main()
{
Right Shift Operator // a = 5(00000101), b = 9(00001001)
Right shift operator shifts all bits towards right by unsigned char a = 5, b = 9;
certain number of specified bits. It is denoted // The result is 00001010
by >>. printf("a<<1 = %d\n", (a << 1));
// The result is 00010010
Left Shift Operator printf("b<<1 = %d", (b << 1));
Left shift operator shifts all bits towards left by return 0;
certain number of specified bits. It is denoted by }
<<.
Output
. a<<1 = 10
b<<1 = 18
Special Operators

1 ) Comma Operator :The comma operator is used


to separate the statement elements such as 2 ) Sizeof Operator : The sizeof() is a unary
variables, constants or expressions, and this operator, that returns the length in bytes o the
operator is used to link the related expressions specified variable, and it is very useful to find the
together, such expressions can be evaluated from bytes occupied by the specified variable in the
left to right and the value of right most memory.
expressions is the value of combined expressions
Syntax : sizeof(variable-name);
int a;
Ex : val(a=3, b=9, c=77, a+c) Ex : sizeof(a); //OUTPUT-----2bytes
First signs the value 3 to a, then assigns 9 to b,
then assigns 77 to c, and finaly80(3+77) to #include <stdio.h>
value. int main()
{
. printf("%lu\n", sizeof(char));
printf("%lu\n", sizeof(int));
printf("%lu\n", sizeof(float));
printf("%lu", sizeof(double));
return 0;
Special Operators

#include <stdio.h> Output


int main() Size of int = 4 bytes
{ Size of float = 4 bytes
int a, e[10]; Size of double = 8 bytes
float b; Size of char = 1 byte
double c;
Size of integer type array having 10 elements = 40
char d;
printf("Size of int=%lu bytes\n",sizeof(a));
bytes
printf("Size of float=%lu bytes\n",sizeof(b));
printf("Size of double=%lu bytes\n",sizeof(c));
printf("Size of char=%lu byte\n",sizeof(d));
printf("Size of integer type array having 10
elements = %lu bytes\n", sizeof(e));
return. 0;
}
Expressions

Expressions : An expression is a combination of operators and operands which reduces to a


single value. An operator indicats an operation to be performed on data that yields a value. An
operand is a data item on which an operation is performed.
Operator Precedence and Associativity :
Operator Precedence

Operator Precedence : Arithmetic Operators are


evaluvated left to right using the 9-12/(3+3)*(2-1)
precedence of operator when the expression is
written without the paranthesis.They are two 1st phase :
levels of arithmetic operators in C. 1 : 9-12/6*(2-1)
1 : High Priority * / % 2 : 9-12/6*1
2 : Low Priority +
2nd phase :
Ex : a=x-y/3+z*2+p/4.
1 : 9-2*1
x=7, y=9, z=11, p=8. 2 : 9-2.
a= 7-9/3+11*2+8/4. 3rd phase :
1 : 7.
1 : a = 7-3+11*2+8/4
2 : a = 7-3+22+8/4
3 : a = 7-3+22+2:
1 : a = 4+22+2
2 : a = 26+2
3 : a = 28
Type Conversion/Type casting

Type conversion is used to convert variable from


one data type to another data type, and after #include <stdio.h>
type casting complier treats the variable as of new int main()
data type. {
printf( "%c\n", (char)65 );
return 0;
Without Type Casting:
}
1. int f= 9/4;
2. printf("f : %d\n", f );//Output: 2 Output
A
With Type Casting:
1. float f=(float) 9/4;
2. printf("f : %f\n", f );//Output: 2.250000
Type Conversion/Type casting

Type conversion in c can be classified into the


following two types:

1. Implicit Type Conversion


When the type conversion is performed
automatically by the compiler without programmers
intervention, such type of conversion is known as
implicit type conversion or type promotion.
Type Conversion/Type casting

#include <stdio.h>
int main() Output
{ x = 107, z = 108.000000
int x = 10; // integer x
char y = 'a'; // character c

// y implicitly converted to int. ASCII


// value of 'a' is 97
x = x + y;

// x is implicitly converted to float


float z = x + 1.0;

printf("x = %d, z = %f", x, z);


return 0;
}
Type Conversion/Type casting

2. Explicit Type Conversion


The type conversion performed by the programmer #include<stdio.h>
by posing the data type of the expression of
specific type is known as explicit type conversion. int main()
The explicit type conversion is also known as {
type casting double x = 1.2;

// Explicit conversion from double to int


int sum = (int)x + 1;

printf("sum = %d", sum);

return 0;
}

Output
sum = 2

You might also like