Assignment 2 Solved
Assignment 2 Solved
ASSIGNMENT NO:- 2
SEMESTER: 2nd
BRANCH: CSE/CST
MAX MARKS: 20
Q1.
In C, when we use call by reference, we pass the address of variables to a function. Changes made
Example:
#include <stdio.h>
int temp;
temp = *a;
*a = *b;
*b = temp;
int main() {
swap(&x, &y);
In C, functions can take arguments which allow passing information to them when they are called.
Example:
#include <stdio.h>
int main() {
display(25);
return 0;
Q2.
#include <stdio.h>
int factorial(int n) {
if (n == 0)
return 1;
else
int main() {
int number;
printf("Enter a number: ");
scanf("%d", &number);
return 0;
#include <stdio.h>
int main() {
int number;
scanf("%d", &number);
multiplicationTable(number);
return 0;
Q3.
Example:
#include <stdio.h>
int main() {
int x = 5;
int *p = &x;
return 0;
(B) What is the difference between array of pointers and pointer to an array?
Examples:
Q4.
Steps:
#include <stdio.h>
int main() {
FILE *fp;
fp = fopen("example.txt", "w");
fclose(fp);
return 0;
Example:
#include <stdio.h>
#include <stdlib.h>
int main() {
int *ptr;
if (ptr == NULL) {
return 1;
free(ptr);
return 0;