Professional Documents
Culture Documents
ANS
1-dimensional array:
a 1-dimensional array is a sequential collection of
elements of the same data type grouped under a single
variable name. It is a fixed-size array where the size is
determined during declaration. The elements in a 1-
dimensional array are stored in continuous blocks of
memory, and each element can be accessed using its
index. The index ranges from 0 to (size-1), and the array
name works as a pointer variable, pointing to the base
address of the array.
ANS
Array definition:
an array is a fixed-size sequential collection of elements
of the same data type grouped under a single variable
name. It allows us to store multiple values of the same
type in a single variable. For example, we can declare
an array of integers as
int rollno[100]
, where
rollno
is the name of the array and it can store 100 integer
values.
Example:
L.D.P.
let's consider an example where we declare an array
a
of size 10 and a pointer variable
p
. In this case,
a[0]
is the same as
*(a+0)
,
a[2]
is the same as
*(a+2)
, and
a[i]
is the same as
*(a+i)
. The array
a
L.D.P.
is allocated continuous blocks of memory, and the
address of the first element is assigned to the array
name. So,
a
works as a pointer variable.
ANS
method 1:
char name[10] = {'u', 'v', 'p', 'c', 'e', '\0'};
method 2:
char name[10] = "uvpce";
(in this method, the null character '\0' will be
automatically inserted at the end of the string. )
ANS
ANS
ANS
ANS
ANS
fib(0) = 0
fib(1) = 1
fib(n) = fib(n-1) + fib(n-2)
for example, to find the 4th number in the fibonacci
series (fib(4)), we can use the recursive formula:
ANS
Function parameters
Call by value
Call by reference/address
L.D.P.
in call by reference/address, the references or
addresses of the parameters are passed to the
function. This allows the function to directly access and
modify the original values of the parameters outside
the function.
ANS
Pass-by-value:
L.D.P.
in pass-by-value, the values of the variables are passed
as function arguments. This means that a copy of the
values is made and passed to the function. Any changes
made to the parameters inside the function do not
affect the original variables outside the function. The
original variables remain unchanged.
Pass-by-reference:
in pass-by-reference, the references or addresses of the
variables are passed as function arguments. This means
that the function can directly access and modify the
original variables using their addresses. Any changes
made to the parameters inside the function will affect
the original variables outside the function. The original
variables can be modified.
ANS
2. Recursive functions
recursive functions are functions that call themselves
within their own definition. They are used to solve
problems that can be divided into smaller
subproblems. These functions have a base case that
stops the recursion and a recursive case that calls the
function again with a smaller input. They are often
L.D.P.
used to solve mathematical problems or perform
repetitive tasks.
3. Pointer to functions
pointer to functions are variables that store the
address of a function. They can be used to access and
call a function indirectly. By using a pointer to a
function, we can pass functions as arguments to other
functions or store them in data structures. This allows
for more flexibility and dynamic behavior in
programming.
ANS
Pre-processing recursion
Macros
L.D.P.
macros are preprocessor directives that allow for the
definition and use of reusable code snippets in a
program. They are typically used to define constants or
to create shortcuts for repetitive tasks. Macros can be
used to simplify the implementation of recursive
functions by providing a way to define recursive calls in
a more concise and readable manner. They can also be
used to define recursive algorithms or to perform
recursive calculations. Macros are a powerful tool in
programming that can enhance the efficiency and
readability of code.
ANS