Chapter One Overview of Programming
Chapter One Overview of Programming
Programming Concepts
A. int x (20);
B. float x{10.8};
C. int c=d=s=f=50;
D. int a=(b=5,b+4);
Q2. what are Typedef and enum with examples?
Ataklti N. 05/16/2025 2
Q3. Which one is the following valid initialization of integer
literals ?
A. int a=10;
B. int b=012;
C. int c=0x12;
D. All of the above
Q4. What will be display from the above statements
E. cout<<c<<"\t"<<b<<'\t'<<a<<endl;
F. int f=9;
bool bf=true;
cout<<f%bf;
Ataklti N. 05/16/2025 3
Q3. float c=10e-3; is valid initialization for floating
number and what is the value of c?
Ataklti N. 05/16/2025 4
1.1. Functions
A function is nothing but a group of codes written together and given
a name. or
A function is a block of code that performs a specific task.
And these can be called anytime in the main function without typing
the whole code.
Why Functions?
Functions make the code reusable.
Declare them once and use them multiple times.
Functions make the program easier as each small task is divided into
a function.
Functions
Ataklti N.
increase readability. 05/16/2025 5
Continued…
• When the function is invoked from any part of the program, it all executes
the codes defined in the body of the function.
• Function declaration
• Calling functions
1.2.1 Function Prototype
• A function prototype comprises type and name of the function along with
list of types of its parameters enclosed in brackets.
• It ends with a semicolon
• Syntax: type identifier (type-of- parameter1, type-of-parameter2, …
type-of- parameter n );
• The prototype conveys the following information to the compiler.
(i) The type of function, i.e. the type of return value.
(ii) Number of parameters of the function.
(iii) Type of each parameter.
(iv) The order in which the arguments would be placed when the
05/16/2025 Ataklti N. 8
Continued…
Ataklti N. 05/16/2025 10
1.2.3 Function Arguments
Sr.
Call Type & Description
No
Call by Value. This method copies the actual value of an argument
into the formal parameter of the function.
1 In this case, changes made to the parameter inside the function have
no effect on the argument.
Call by Pointer. This method copies the address of an argument into
the formal parameter.
2 Inside the function, the address is used to access the actual argument
used in the call.
This means that changes made to the parameter affect the argument.
Ataklti N. 05/16/2025 13
1.2.6 C++ Programming Default Arguments
(Parameters)
• In C++ programming, we can provide default values for function
parameters.
• In C++, functions can also have optional parameters, for which no
arguments are required in the call, in such a way that,
• for example, a function with three parameters may be called with
only two.
• For this, the function shall include a default value for its last
parameter, which is used by the function when called with fewer
arguments.
• If a function with default arguments is called without passing
arguments, then the default parameters are used.
Ataklti N. 05/16/2025 14
1.2.7 C++ Recursion
• Recursively is the property that functions have to be called by
themselves.
Ataklti N. 05/16/2025 15
Advantages of C++ Recursion
• It makes the code shorter and cleaner.
• Recursion is required in problems concerning data structures and
advanced algorithms, such as sorting, Graph and Tree
Traversal.
Ataklti N. 05/16/2025 20
C++ Array Initialization
Ataklti N. 05/16/2025 22
Passing Array to a Function in C++ Programming
Ataklti N. 05/16/2025 23
C++ Strings
• String is a collection of characters.
• String is nothing but a sequence of character in which the last
character is the null character ‘\0’.
Ataklti N. 05/16/2025 28
1.5 Structure in C++
• structure is another user defined data type which allows you to
combine data items of different kinds.
• Structures are used to represent a record
• A Structure is a collection of simple variables.
• The Variables in a structure can be of different types.
• Some can be int, some can be float, and so on.
• The data items in a structure are called the members of the
structure.
• Declaration of structure
• To define a structure, you must use the struct statement.
• The struct statement defines a new data type, with more than one
Ataklti N. 05/16/2025 29
member
Continued…
• struct [structure tag]
• {
member definition;
member definition;
...
member definition;
} [one or more structure variables];
Ataklti N. 05/16/2025 30
Initialization of structure and
Accessing of structure
• To access any member of a structure, we use the member
access operator (.).
Ataklti N. 05/16/2025 31
Pointers and structures
• To access the members of a structure using a
pointer to that structure, you must use the
(Arrow)-> operator as follows:
Ataklti N. 05/16/2025 32