SlideShare a Scribd company logo
1 of 84
Download to read offline
MCA 101
Programming in C with Data Structure
UNIT I
Prof. Rohit Dubey
MCA 101
Programming in with Data Structure
UNIT I
Fundamentals of C Programming :
Structure of a C Program, Data types, Identifiers and keywords,
Operators & expressions, Preprocessor directive, Input output,
Casting, Precedence, Scope of variables Control Constructs and
Iteration Constructs Functions: Defining and accessing: passing
arguments, Function prototypes, Recursion, Storage classes
Structure of a C Program
To find the sum of two numbers given by the user
It is given by:
/* Sum of two numbers */
#include<stdio.h>
int main()
{
int a, b, sum;
printf("Enter two numbers to be added ");
scanf("%d %d", &a, &b);
// calculating sum
sum = a + b;
printf("%d + %d = %d", a, b, sum);
return 0; // return the integer value in the sum
}
* conio.h is a C header file used mostly by MS-DOS
compilers to provide console input/output. It is not part
of the C standard library or ISO C, nor is it defined by
POSIX. This header declares several useful library
functions for performing "istream input and output" from
a program.
Output
Data Types in C
• A data type specifies the type of data that a variable can store such as
integer, floating, character, etc.
Basic Data Types
• The basic data types are integer-based and floating-point based. C
language supports both signed and unsigned literals.
• The memory size of the basic data types may change according to 32
or 64-bit operating system.
• Let's see the basic data types. Its size is given according to 32-bit
architecture.
C Identifiers
• C identifiers represent the name in the C program, for example,
variables, functions, arrays, structures, unions, labels, etc. An
identifier can be composed of letters such as uppercase, lowercase
letters, underscore, digits, but the starting letter should be either an
alphabet or an underscore. If the identifier is not used in the external
linkage, then it is called as an internal identifier. If the identifier is
used in the external linkage, then it is called as an external identifier.
• We can say that an identifier is a collection of alphanumeric
characters that begins either with an alphabetical character or an
underscore, which are used to represent various programming
elements such as variables, functions, arrays, structures, unions,
labels, etc. There are 52 alphabetical characters (uppercase and
lowercase), underscore character, and ten numerical digits (0-9) that
represent the identifiers. There is a total of 63 alphanumerical
characters that represent the identifiers.
Rules for constructing C identifiers
• The first character of an identifier should be either an alphabet or an
underscore, and then it can be followed by any of the character, digit, or
underscore.
• It should not begin with any numerical digit.
• In identifiers, both uppercase and lowercase letters are distinct. Therefore,
we can say that identifiers are case sensitive.
• Commas or blank spaces cannot be specified within an identifier.
• Keywords cannot be represented as an identifier.
• The length of the identifiers should not be more than 31 characters.
• Identifiers should be written in such a way that it is meaningful, short, and
easy to read.
Example of valid identifiers
1.total, sum, average, _m _, sum_1, etc.
Example of invalid identifiers
1.2sum (starts with a numerical digit)
2.int (reserved word)
3.char (reserved word)
4.m+n (special character, i.e., '+')
Types of identifiers
• Internal Identifier
• If the identifier is not used in the external linkage, then it is known as
an internal identifier. The internal identifiers can be local variables.
• External Identifier
• If the identifier is used in the external linkage, then it is known as an
external identifier. The external identifiers can be function names,
global variables.
Let's understand through an example.
int main()
{
int a=10;
int A=20;
printf("Value of a is : %d",a);
printf("nValue of A is :%d",A);
return 0;
}
Output:
• Value of a is : 10
• Value of A is :20
• The above output shows that the values of both the variables, 'a' and
'A' are different. Therefore, we conclude that the identifiers are case
sensitive.
Keywords in C
• A keyword is a reserved word. You cannot use it as a variable name,
constant name, etc. There are only 32 reserved words (keywords) in
the C language.
• A list of 32 keywords in the c language is given below:
Keywords in C
// C program to demonstrate
// auto keyword
#include <stdio.h>
int printvalue()
{
auto int a = 10;
printf("%d", a);
}
// Driver code
int main()
{
printvalue();
return 0;
}
C Operators:
An operator is simply a symbol that is used to perform operations. There
can be many types of operations like arithmetic, logical, bitwise, etc.
• There are following types of operators to perform different types of
operations in C language.
• Arithmetic Operators
• Relational Operators
• Shift Operators
C Operators:
• Logical Operators
• Bitwise Operators
• Ternary or Conditional Operators
• Assignment Operator
• Misc Operator
Precedence of Operators in C
• The precedence of operator species that which operator will be
evaluated first and next. The associativity specifies the operator
direction to be evaluated; it may be left to right or right to left.
• Let's understand the precedence by the example given below:
int value=10+20*10;
• The value variable will contain 210 because * (multiplicative operator)
is evaluated before + (additive operator).
• The precedence and associativity of C operators is given below:
C - Preprocessors
• The C Preprocessor is not a part of the compiler, but is a separate step
in the compilation process. In simple terms, a C Preprocessor is just a
text substitution tool and it instructs the compiler to do required pre-
processing before the actual compilation. We'll refer to the C
Preprocessor as CPP.
• All preprocessor commands begin with a hash symbol (#). It
must be the first nonblank character, and for readability, a
preprocessor directive should begin in the first column. The
following section lists down all the important preprocessor
directives −
C Input Output (I/O)
• In C programming, printf() is one of the main output function. The
function sends formatted output to the screen. For example,
How does this program work?
• All valid C programs must contain the main() function. The code
execution begins from the start of the main() function.
• The printf() is a library function to send formatted output to the
screen. The function prints the string inside quotations.
• To use printf() in our program, we need to include stdio.h header file
using the #include <stdio.h> statement.
• The return 0; statement inside the main() function is the "Exit status"
of the program. It's optional.
C Input
• In C programming, scanf() is one of the commonly used function to
take input from the user. The scanf() function reads formatted input
from the standard input such as keyboards.
C - Type Casting
• Converting one datatype into another is known as type casting
or, type-conversion. For example, if you want to store a 'long'
value into a simple integer then you can type cast 'long' to 'int'.
You can convert the values from one type to another explicitly
using the cast operator as follows −
Without Type Casting:
int f= 9/4;
printf("f : %dn", f );//Output: 2
With Type Casting:
float f=(float) 9/4;
printf("f : %fn", f );//Output: 2.250000
Type Casting example
Let's see a simple example to cast int value into the float.
#include<stdio.h>
int main(){
float f= (float)9/4;
printf("f : %fn", f );
return 0;
}
Output:
f : 2.250000
Operator precedence
• Operator precedence determines the grouping of terms in an
expression and decides how an expression is evaluated.
Certain operators have higher precedence than others; for
example, the multiplication operator has a higher precedence
than the addition operator.
• For example, x = 7 + 3 * 2; here, x is assigned 13, not 20
because operator * has a higher precedence than +, so it first
gets multiplied with 3*2 and then adds into 7.
Operator precedence
• For example, x = 7 + 3 * 2; here, x is assigned 13, not 20
because operator * has a higher precedence than +, so it first
gets multiplied with 3*2 and then adds into 7.
• Here, operators with the highest precedence appear at the top
of the table, those with the lowest appear at the bottom.
Within an expression, higher precedence operators will be
evaluated first.
• When you compile and execute the above program, it produces the
following result −
• Value of (a + b) * c / d is : 90
• Value of ((a + b) * c) / d is : 90
• Value of (a + b) * (c / d) is : 90
• Value of a + (b * c) / d is : 50
C variable scope
• In C programming, every variable is defined in scope. You can define scope as the
section or region of a program where a variable has its existence; moreover, that
variable cannot be used or accessed beyond that region. In C programming, a
variable declared within a function differs from a variable declared outside of a
function. The variable can be declared in three places. These are:
Local Variables
• Variables that are declared within the function block and can be used
only within the function are called local variables.
• All these locally scoped statements are written and enclosed
within the left ({) and right (}) curly braces. C also has a provision
for nested blocks, which means that a block or function can
occur within another block or function. So it means that
variables declared within a block can be accessed within that
specific block and all other internal blocks of that block but
cannot be accessed outside the block.
Global Variables
• In most cases, global variables are defined outside a function or any
specific block on top of the C program. These variables hold their
values all through the end of the program and are accessible within
any of the functions defined in your program. Any function can access
variables defined within the global scope, i.e., its availability stays for
the entire program after being declared.
Function prototype
• A function prototype is simply the declaration of a function that
specifies function's name, parameters and return type. It doesn't
contain function body.
• A function prototype gives information to the compiler that the
function may later be used in the program.
Syntax of function prototype
Function definition
• Passing arguments to a function
• In programming, argument refers to the variable passed to the
function. In the above example, two variables n1 and n2 are passed
during the function call.
• The parameters a and b accepts the passed arguments in the function
definition. These arguments are called formal parameters of the
function.
The type of arguments passed to a
function and the formal parameters
must match, otherwise, the compiler
will throw an error.
If n1 is of char type, a also should be
of char type. If n2 is of float type,
variable b also should be of float type.
A function can also be called without
passing an argument.
Return Statement
• Return Statement
• The return statement terminates the execution of a function and
returns a value to the calling function. The program control is
transferred to the calling function after the return statement.
• In the above example, the value of the result variable is returned to
the main function. The sum variable in the main() function is assigned
this value.
Parameter Passing Techniques in C/C++
• There are different ways in which parameter data can be passed into
and out of methods and functions. Let us assume that a function B()
is called from another function A(). In this case A is called the “caller
function” and B is called the “called function or callee function”. Also,
the arguments which A sends to B are called actual arguments and
the parameters of B are called formal arguments.
Terminology
• Formal Parameter : A variable and its type as they appear in the prototype
of the function or method.
• Actual Parameter : The variable or expression corresponding to a formal
parameter that appears in the function or method call in the calling
environment.
• Modes:
• IN: Passes info from caller to callee.
• OUT: Callee writes values in caller.
• IN/OUT: Caller tells callee value of variable, which may be updated by
callee.
Important methods of Parameter Passing
• Pass By Value: This method uses in-mode semantics. Changes made
to formal parameter do not get transmitted back to the caller. Any
modifications to the formal parameter variable inside the called
function or method affect only the separate storage location and will
not be reflected in the actual parameter in the calling environment.
This method is also called as call by value.
• Pass by reference(aliasing): This technique uses in/out-mode
semantics. Changes made to formal parameter do get transmitted
back to the caller through parameter passing. Any changes to the
formal parameter are reflected in the actual parameter in the calling
environment as formal parameter receives a reference (or pointer) to
the actual data. This method is also called as call by reference. This
method is efficient in both time and space.
Recursion
• Recursion is the technique of making a function call
itself. This technique provides a way to break
complicated problems down into simple problems which
are easier to solve.
• Recursion may be a bit difficult to understand. The best
way to figure out how it works is to experiment with it.
o/p: 55
Example Explained
• When the sum() function is called, it adds parameter k to the sum of
all numbers smaller than k and returns the result. When k becomes 0,
the function just returns 0. When running, the program follows these
steps
• Since the function does not call itself when k is 0, the program
stops there and returns the result.
C - Storage Classes
• A storage class defines the scope (visibility) and life-time of
variables and/or functions within a C Program. They precede
the type that they modify. We have four different storage
classes in a C program −
• auto
• register
• static
• extern
The auto Storage Class
The auto storage class is the default storage class for all local variables.
{
int mount;
auto int month;
}
The example above defines two variables with in the same storage
class. 'auto' can only be used within functions, i.e., local variables.
The register Storage Class
The register storage class is used to define local variables that should
be stored in a register instead of RAM. This means that the variable has
a maximum size equal to the register size (usually one word) and can't
have the unary '&' operator applied to it (as it does not have a memory
location).
{
register int miles;
}
The static Storage Class
The static storage class instructs the compiler to keep a local variable in existence during the
life-time of the program instead of creating and destroying it each time it comes into and goes
out of scope. Therefore, making local variables static allows them to maintain their values
between function calls.
The static modifier may also be applied to global variables. When this is done, it causes that
variable's scope to be restricted to the file in which it is declared.
In C programming, when static is used on a global variable, it causes only one copy of that
member to be shared by all the objects of its class.
The extern Storage Class
• The extern storage class is used to give a reference of a global
variable that is visible to ALL the program files. When you use
'extern', the variable cannot be initialized however, it points the
variable name at a storage location that has been previously
defined.
• When you have multiple files and you define a global variable
or function, which will also be used in other files,
then extern will be used in another file to provide the reference
of defined variable or function. Just for understanding, extern is
used to declare a global variable or function in another file.
• The extern modifier is most commonly used when there are two or
more files sharing the same global variables or functions as
explained below.
MCA 101
Programming in C with Data Structure
UNIT I
Prof. Rohit Dubey
Thank You

More Related Content

What's hot

Control statements
Control statementsControl statements
Control statementsraksharao
 
Transaction Processing its properties & States
Transaction Processing its properties & StatesTransaction Processing its properties & States
Transaction Processing its properties & StatesMeghaj Mallick
 
Event Driven programming(ch1 and ch2).pdf
Event Driven programming(ch1 and ch2).pdfEvent Driven programming(ch1 and ch2).pdf
Event Driven programming(ch1 and ch2).pdfAliEndris3
 
Network and System Administration chapter 2
Network and System Administration chapter 2Network and System Administration chapter 2
Network and System Administration chapter 2IgguuMuude
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++Neeru Mittal
 
C++ Pointers And References
C++ Pointers And ReferencesC++ Pointers And References
C++ Pointers And Referencesverisan
 
Context Switching
Context SwitchingContext Switching
Context Switchingfranksvalli
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programmingprogramming9
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming LanguageAhmad Idrees
 
Database Programming
Database ProgrammingDatabase Programming
Database ProgrammingHenry Osborne
 
Assembly language programming(unit 4)
Assembly language programming(unit 4)Assembly language programming(unit 4)
Assembly language programming(unit 4)Ashim Saha
 
Operating system services 9
Operating system services 9Operating system services 9
Operating system services 9myrajendra
 
Computer Architecture - Program Execution
Computer Architecture - Program ExecutionComputer Architecture - Program Execution
Computer Architecture - Program ExecutionVarun Bhargava
 

What's hot (20)

Control statements
Control statementsControl statements
Control statements
 
Windowforms controls c#
Windowforms controls c#Windowforms controls c#
Windowforms controls c#
 
Timing and control
Timing and controlTiming and control
Timing and control
 
Transaction Processing its properties & States
Transaction Processing its properties & StatesTransaction Processing its properties & States
Transaction Processing its properties & States
 
Event Driven programming(ch1 and ch2).pdf
Event Driven programming(ch1 and ch2).pdfEvent Driven programming(ch1 and ch2).pdf
Event Driven programming(ch1 and ch2).pdf
 
Network and System Administration chapter 2
Network and System Administration chapter 2Network and System Administration chapter 2
Network and System Administration chapter 2
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
C++ Pointers And References
C++ Pointers And ReferencesC++ Pointers And References
C++ Pointers And References
 
process control block
process control blockprocess control block
process control block
 
Context Switching
Context SwitchingContext Switching
Context Switching
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
Instruction code
Instruction codeInstruction code
Instruction code
 
Internet Protocols
Internet ProtocolsInternet Protocols
Internet Protocols
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
 
Cpu organisation
Cpu organisationCpu organisation
Cpu organisation
 
Database Programming
Database ProgrammingDatabase Programming
Database Programming
 
Assembly language programming(unit 4)
Assembly language programming(unit 4)Assembly language programming(unit 4)
Assembly language programming(unit 4)
 
Operating system services 9
Operating system services 9Operating system services 9
Operating system services 9
 
Computer Architecture - Program Execution
Computer Architecture - Program ExecutionComputer Architecture - Program Execution
Computer Architecture - Program Execution
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 

Similar to MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey

Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C ProgrammingMOHAMAD NOH AHMAD
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 FocJAYA
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxLikhil181
 
INTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptxINTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptxMamataAnilgod
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageDr.Florence Dayana
 
C programming language
C programming languageC programming language
C programming languageAbin Rimal
 
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...RSathyaPriyaCSEKIOT
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.pptTanuGohel
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.pptMEHALAS3
 
Basics of C (1).ppt
Basics of C (1).pptBasics of C (1).ppt
Basics of C (1).pptSteveIrwin25
 

Similar to MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey (20)

C programming
C programmingC programming
C programming
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 
Module 1 PCD.docx
Module 1 PCD.docxModule 1 PCD.docx
Module 1 PCD.docx
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
 
INTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptxINTRODUCTION TO C++.pptx
INTRODUCTION TO C++.pptx
 
M.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C LanguageM.Florence Dayana / Basics of C Language
M.Florence Dayana / Basics of C Language
 
#Code2 create c++ for beginners
#Code2 create  c++ for beginners #Code2 create  c++ for beginners
#Code2 create c++ for beginners
 
C programming language
C programming languageC programming language
C programming language
 
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
 
Cpu
CpuCpu
Cpu
 
C programming.pdf
C programming.pdfC programming.pdf
C programming.pdf
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Funa-C.ppt
Funa-C.pptFuna-C.ppt
Funa-C.ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 
Basics of C (1).ppt
Basics of C (1).pptBasics of C (1).ppt
Basics of C (1).ppt
 
Basics of C.ppt
Basics of C.pptBasics of C.ppt
Basics of C.ppt
 

Recently uploaded

Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 

Recently uploaded (20)

Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 

MCA 101-Programming in C with Data Structure UNIT I by Prof. Rohit Dubey

  • 1. MCA 101 Programming in C with Data Structure UNIT I Prof. Rohit Dubey
  • 2. MCA 101 Programming in with Data Structure UNIT I Fundamentals of C Programming : Structure of a C Program, Data types, Identifiers and keywords, Operators & expressions, Preprocessor directive, Input output, Casting, Precedence, Scope of variables Control Constructs and Iteration Constructs Functions: Defining and accessing: passing arguments, Function prototypes, Recursion, Storage classes
  • 3. Structure of a C Program To find the sum of two numbers given by the user It is given by: /* Sum of two numbers */ #include<stdio.h> int main() { int a, b, sum; printf("Enter two numbers to be added "); scanf("%d %d", &a, &b); // calculating sum sum = a + b; printf("%d + %d = %d", a, b, sum); return 0; // return the integer value in the sum } * conio.h is a C header file used mostly by MS-DOS compilers to provide console input/output. It is not part of the C standard library or ISO C, nor is it defined by POSIX. This header declares several useful library functions for performing "istream input and output" from a program.
  • 5.
  • 6. Data Types in C • A data type specifies the type of data that a variable can store such as integer, floating, character, etc.
  • 7. Basic Data Types • The basic data types are integer-based and floating-point based. C language supports both signed and unsigned literals. • The memory size of the basic data types may change according to 32 or 64-bit operating system. • Let's see the basic data types. Its size is given according to 32-bit architecture.
  • 8.
  • 9.
  • 10. C Identifiers • C identifiers represent the name in the C program, for example, variables, functions, arrays, structures, unions, labels, etc. An identifier can be composed of letters such as uppercase, lowercase letters, underscore, digits, but the starting letter should be either an alphabet or an underscore. If the identifier is not used in the external linkage, then it is called as an internal identifier. If the identifier is used in the external linkage, then it is called as an external identifier.
  • 11.
  • 12. • We can say that an identifier is a collection of alphanumeric characters that begins either with an alphabetical character or an underscore, which are used to represent various programming elements such as variables, functions, arrays, structures, unions, labels, etc. There are 52 alphabetical characters (uppercase and lowercase), underscore character, and ten numerical digits (0-9) that represent the identifiers. There is a total of 63 alphanumerical characters that represent the identifiers.
  • 13. Rules for constructing C identifiers • The first character of an identifier should be either an alphabet or an underscore, and then it can be followed by any of the character, digit, or underscore. • It should not begin with any numerical digit. • In identifiers, both uppercase and lowercase letters are distinct. Therefore, we can say that identifiers are case sensitive. • Commas or blank spaces cannot be specified within an identifier. • Keywords cannot be represented as an identifier. • The length of the identifiers should not be more than 31 characters. • Identifiers should be written in such a way that it is meaningful, short, and easy to read.
  • 14. Example of valid identifiers 1.total, sum, average, _m _, sum_1, etc. Example of invalid identifiers 1.2sum (starts with a numerical digit) 2.int (reserved word) 3.char (reserved word) 4.m+n (special character, i.e., '+')
  • 15. Types of identifiers • Internal Identifier • If the identifier is not used in the external linkage, then it is known as an internal identifier. The internal identifiers can be local variables. • External Identifier • If the identifier is used in the external linkage, then it is known as an external identifier. The external identifiers can be function names, global variables.
  • 16.
  • 17. Let's understand through an example. int main() { int a=10; int A=20; printf("Value of a is : %d",a); printf("nValue of A is :%d",A); return 0; }
  • 18. Output: • Value of a is : 10 • Value of A is :20 • The above output shows that the values of both the variables, 'a' and 'A' are different. Therefore, we conclude that the identifiers are case sensitive.
  • 19. Keywords in C • A keyword is a reserved word. You cannot use it as a variable name, constant name, etc. There are only 32 reserved words (keywords) in the C language. • A list of 32 keywords in the c language is given below:
  • 21. // C program to demonstrate // auto keyword #include <stdio.h> int printvalue() { auto int a = 10; printf("%d", a); } // Driver code int main() { printvalue(); return 0; }
  • 22. C Operators: An operator is simply a symbol that is used to perform operations. There can be many types of operations like arithmetic, logical, bitwise, etc. • There are following types of operators to perform different types of operations in C language. • Arithmetic Operators • Relational Operators • Shift Operators
  • 23. C Operators: • Logical Operators • Bitwise Operators • Ternary or Conditional Operators • Assignment Operator • Misc Operator
  • 24. Precedence of Operators in C • The precedence of operator species that which operator will be evaluated first and next. The associativity specifies the operator direction to be evaluated; it may be left to right or right to left. • Let's understand the precedence by the example given below: int value=10+20*10; • The value variable will contain 210 because * (multiplicative operator) is evaluated before + (additive operator). • The precedence and associativity of C operators is given below:
  • 25.
  • 26.
  • 27.
  • 28.
  • 29. C - Preprocessors • The C Preprocessor is not a part of the compiler, but is a separate step in the compilation process. In simple terms, a C Preprocessor is just a text substitution tool and it instructs the compiler to do required pre- processing before the actual compilation. We'll refer to the C Preprocessor as CPP. • All preprocessor commands begin with a hash symbol (#). It must be the first nonblank character, and for readability, a preprocessor directive should begin in the first column. The following section lists down all the important preprocessor directives −
  • 30.
  • 31.
  • 32.
  • 33.
  • 34. C Input Output (I/O) • In C programming, printf() is one of the main output function. The function sends formatted output to the screen. For example,
  • 35. How does this program work? • All valid C programs must contain the main() function. The code execution begins from the start of the main() function. • The printf() is a library function to send formatted output to the screen. The function prints the string inside quotations. • To use printf() in our program, we need to include stdio.h header file using the #include <stdio.h> statement. • The return 0; statement inside the main() function is the "Exit status" of the program. It's optional.
  • 36.
  • 37.
  • 38. C Input • In C programming, scanf() is one of the commonly used function to take input from the user. The scanf() function reads formatted input from the standard input such as keyboards.
  • 39.
  • 40.
  • 41. C - Type Casting • Converting one datatype into another is known as type casting or, type-conversion. For example, if you want to store a 'long' value into a simple integer then you can type cast 'long' to 'int'. You can convert the values from one type to another explicitly using the cast operator as follows − Without Type Casting: int f= 9/4; printf("f : %dn", f );//Output: 2 With Type Casting: float f=(float) 9/4; printf("f : %fn", f );//Output: 2.250000
  • 42. Type Casting example Let's see a simple example to cast int value into the float. #include<stdio.h> int main(){ float f= (float)9/4; printf("f : %fn", f ); return 0; } Output: f : 2.250000
  • 43.
  • 44. Operator precedence • Operator precedence determines the grouping of terms in an expression and decides how an expression is evaluated. Certain operators have higher precedence than others; for example, the multiplication operator has a higher precedence than the addition operator. • For example, x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has a higher precedence than +, so it first gets multiplied with 3*2 and then adds into 7.
  • 45. Operator precedence • For example, x = 7 + 3 * 2; here, x is assigned 13, not 20 because operator * has a higher precedence than +, so it first gets multiplied with 3*2 and then adds into 7. • Here, operators with the highest precedence appear at the top of the table, those with the lowest appear at the bottom. Within an expression, higher precedence operators will be evaluated first.
  • 46.
  • 47. • When you compile and execute the above program, it produces the following result − • Value of (a + b) * c / d is : 90 • Value of ((a + b) * c) / d is : 90 • Value of (a + b) * (c / d) is : 90 • Value of a + (b * c) / d is : 50
  • 48. C variable scope • In C programming, every variable is defined in scope. You can define scope as the section or region of a program where a variable has its existence; moreover, that variable cannot be used or accessed beyond that region. In C programming, a variable declared within a function differs from a variable declared outside of a function. The variable can be declared in three places. These are:
  • 49. Local Variables • Variables that are declared within the function block and can be used only within the function are called local variables. • All these locally scoped statements are written and enclosed within the left ({) and right (}) curly braces. C also has a provision for nested blocks, which means that a block or function can occur within another block or function. So it means that variables declared within a block can be accessed within that specific block and all other internal blocks of that block but cannot be accessed outside the block.
  • 50.
  • 51. Global Variables • In most cases, global variables are defined outside a function or any specific block on top of the C program. These variables hold their values all through the end of the program and are accessible within any of the functions defined in your program. Any function can access variables defined within the global scope, i.e., its availability stays for the entire program after being declared.
  • 52.
  • 53. Function prototype • A function prototype is simply the declaration of a function that specifies function's name, parameters and return type. It doesn't contain function body. • A function prototype gives information to the compiler that the function may later be used in the program.
  • 54. Syntax of function prototype
  • 56. • Passing arguments to a function • In programming, argument refers to the variable passed to the function. In the above example, two variables n1 and n2 are passed during the function call. • The parameters a and b accepts the passed arguments in the function definition. These arguments are called formal parameters of the function.
  • 57. The type of arguments passed to a function and the formal parameters must match, otherwise, the compiler will throw an error. If n1 is of char type, a also should be of char type. If n2 is of float type, variable b also should be of float type. A function can also be called without passing an argument.
  • 58. Return Statement • Return Statement • The return statement terminates the execution of a function and returns a value to the calling function. The program control is transferred to the calling function after the return statement. • In the above example, the value of the result variable is returned to the main function. The sum variable in the main() function is assigned this value.
  • 59.
  • 60. Parameter Passing Techniques in C/C++ • There are different ways in which parameter data can be passed into and out of methods and functions. Let us assume that a function B() is called from another function A(). In this case A is called the “caller function” and B is called the “called function or callee function”. Also, the arguments which A sends to B are called actual arguments and the parameters of B are called formal arguments.
  • 61. Terminology • Formal Parameter : A variable and its type as they appear in the prototype of the function or method. • Actual Parameter : The variable or expression corresponding to a formal parameter that appears in the function or method call in the calling environment. • Modes: • IN: Passes info from caller to callee. • OUT: Callee writes values in caller. • IN/OUT: Caller tells callee value of variable, which may be updated by callee.
  • 62. Important methods of Parameter Passing • Pass By Value: This method uses in-mode semantics. Changes made to formal parameter do not get transmitted back to the caller. Any modifications to the formal parameter variable inside the called function or method affect only the separate storage location and will not be reflected in the actual parameter in the calling environment. This method is also called as call by value.
  • 63.
  • 64.
  • 65.
  • 66. • Pass by reference(aliasing): This technique uses in/out-mode semantics. Changes made to formal parameter do get transmitted back to the caller through parameter passing. Any changes to the formal parameter are reflected in the actual parameter in the calling environment as formal parameter receives a reference (or pointer) to the actual data. This method is also called as call by reference. This method is efficient in both time and space.
  • 67.
  • 68.
  • 69.
  • 70. Recursion • Recursion is the technique of making a function call itself. This technique provides a way to break complicated problems down into simple problems which are easier to solve. • Recursion may be a bit difficult to understand. The best way to figure out how it works is to experiment with it.
  • 72. Example Explained • When the sum() function is called, it adds parameter k to the sum of all numbers smaller than k and returns the result. When k becomes 0, the function just returns 0. When running, the program follows these steps • Since the function does not call itself when k is 0, the program stops there and returns the result.
  • 73.
  • 74. C - Storage Classes • A storage class defines the scope (visibility) and life-time of variables and/or functions within a C Program. They precede the type that they modify. We have four different storage classes in a C program − • auto • register • static • extern
  • 75. The auto Storage Class The auto storage class is the default storage class for all local variables. { int mount; auto int month; } The example above defines two variables with in the same storage class. 'auto' can only be used within functions, i.e., local variables.
  • 76. The register Storage Class The register storage class is used to define local variables that should be stored in a register instead of RAM. This means that the variable has a maximum size equal to the register size (usually one word) and can't have the unary '&' operator applied to it (as it does not have a memory location). { register int miles; }
  • 77. The static Storage Class The static storage class instructs the compiler to keep a local variable in existence during the life-time of the program instead of creating and destroying it each time it comes into and goes out of scope. Therefore, making local variables static allows them to maintain their values between function calls. The static modifier may also be applied to global variables. When this is done, it causes that variable's scope to be restricted to the file in which it is declared. In C programming, when static is used on a global variable, it causes only one copy of that member to be shared by all the objects of its class.
  • 78.
  • 79.
  • 80. The extern Storage Class • The extern storage class is used to give a reference of a global variable that is visible to ALL the program files. When you use 'extern', the variable cannot be initialized however, it points the variable name at a storage location that has been previously defined. • When you have multiple files and you define a global variable or function, which will also be used in other files, then extern will be used in another file to provide the reference of defined variable or function. Just for understanding, extern is used to declare a global variable or function in another file.
  • 81. • The extern modifier is most commonly used when there are two or more files sharing the same global variables or functions as explained below.
  • 82.
  • 83.
  • 84. MCA 101 Programming in C with Data Structure UNIT I Prof. Rohit Dubey Thank You