C - 5 Mark
C - 5 Mark
1. strlen( )
Syntax:
n =strlen (string);
Where n is an integer variable which receives the value of the length of the string.
Example:- int n;
2. strcpy( )
Where string1 is the source string, string2 is the destination string i.e., string1 is
copied to
string2.
char target[20];
This function copies specified length of characters from the source to destination
string.
Example:
strncpy(s2,s1,6);
printf(“%s”, s2);
4. strlwr( )
Syntax:
strlwr(string);
5. strupr()
Syntax:
strupr(string);
6. strcat( )
This function joins(concatenates) two strings together. That is this function appends
the target string to the source string.
Syntax: strcat (string1, string2);
printf(“%s”, s1);
What is Recursion?
2. Recursive Case: The part where the function calls itself with a modified argument.
Types of Recursion
Definition: Direct recursion occurs when a function calls itself directly within its own
body.
#include <stdio.h>
int factorial(int n) {
if (n == 0) { // Base case
return 1;
int main() {
int num = 5;
return 0;
Explanation:
The factorial() function calls itself with n-1 until n reaches 0. This is direct recursion
because the function calls itself directly.
Definition: Indirect recursion occurs when a function calls another function, and that
second function, in turn, calls the first function. This creates a cycle of function calls.
Example: A typical example is two functions where one calls the other, and the second
calls the first.
#include <stdio.h>
void funcA(int n) {
if (n > 0) {
void funcB(int n) {
if (n > 0) {
int main() {
int num = 5;
return 0;
Explanation:
The function funcA() calls funcB(), and funcB() calls funcA(). This mutual calling creates
indirect recursion.
Differentiate between call by value and call by reference with the help of an example.
Call by Value and Call by Reference are two methods of passing arguments to
functions in programming. Here's a breakdown of both concepts along with an
example:
1. Call by Value:
In call by value, the actual value of the argument is passed to the function. The
function works on a copy of the argument, and any modifications made to the
parameter inside the function do not affect the original argument.
def modify_value(x):
x = x + 10
print("Inside function:", x)
a=5
modify_value(a)
print("Outside function:", a)
Output:
Inside function: 15
Outside function: 5
Explanation:
Inside the function, x is modified (incremented by 10), but this does not change the
original value of a outside the function.
2. Call by Reference:
In call by reference, the reference (or address) of the argument is passed to the
function. This means that any modifications made to the parameter inside the function
will affect the original argument, as both the parameter and the argument point to
the same memory location.
def modify_reference(lst):
lst.append(4)
my_list = [1, 2, 3]
modify_reference(my_list)
Output:
Explanation:
Inside the function, an element is added to the list, and this modification reflects in the
original list outside the function as well, because both the parameter lst and the
argument my_list refer to the same object in memory.