Computer Science I
Computer Science I
KANDIVALI(E)
6. Write a C++ program to perform addition of two numbers using user-defined sum ()
function.
#include <iostream.h>
#include <Conio.h>
int sum (int, int)
Void Main ( )
{
clrscr ( );
int a, b;
cout << “enter two number”
cin >> a >> b
int c = Sum(a, b)
cout << “Addition =” << C;
getch ( )
}
int sum (int m, int n)
return (m + n);
}
1. Arithmetic Operators
2. Assignment Operators
3. Relational Operators
4. Logical Operators
5. Bitwise Operators
6. Other Operators
1. Integral types: These are used to store integers. There are several integral types in
C++, including char, short, int, long, and long long.
2. Floating-point types: These are used to store real numbers. The two floating-point
types in C++ are float and double.
3. Boolean type: This is used to store a value that is either true or false. The boolean type
in C++ is bool.
4. Void type: This is a special type used to represent the absence of a value. The void
type is used in function declarations to indicate that the function does not return a
value.
10. What is array? How to initialize array? How to access array elements?
1. An array is a finite set of homogenous data elements.
2. Its elements are stored in a contiguous memory location.
3. The size of the array should be mentioned while declaring it.
4. Array elements are always counted from zero (0) onward.
5. Array elements can be accessed using the position of the element in the array.
6. The array can have one or more dimensions.
The initializer for an array is a comma-separated list of constant expressions enclosed in braces
({}). The initializer is preceded by an equal sign (=). You do not need to initialize all elements in an
array.
You can access an array element by referring to its index number
11. Define pointer. Explain pointer with the help of suitable example.
A pointer is a variable that stores the address of another variable. Unlike other variables that hold
values of a certain type, pointer holds the address of a variable. For example, an integer variable
holds (or you can say stores) an integer value, however an integer pointer holds the address of a
integer variable.
12. Define function. Explain two of each mathematical and string functions.
A function is defined as a relation between a set of inputs having one output each. In simple words, a
function is a relationship between inputs where each input is related to exactly one output. Every
function has a domain and codomain or range. A function is generally denoted by f(x) where x is the
input. The general representation of a function is y = f(x).
These functions are also classified into various types, which we will discuss here. Check Relations and
Functions lesson for more information.
An example of a simple function is f(x) = x2. In this function, the function f(x) takes the value of “x” and
then squares it. For instance, if x = 3, then f (3) = 9. A few more examples of functions are: f(x) = sin x,
f(x) = x2 + 3, f(x) = 1/x, f(x) = 2x + 3, etc.