1- void fun(int &j) { j++- } int main() { int i - 20- fun(i)- printf(-.docx

tjames442 4 views 3 slides Jan 31, 2023
Slide 1
Slide 1 of 3
Slide 1
1
Slide 2
2
Slide 3
3

About This Presentation

1.
void fun(int &j) {
j++;
}
int main() {
int i = 20;
fun(i);
printf(\"i = %d\ \", i);
return 0;
}
2.
void fun(int *j) {
(*j)++;
}
int main() {
int i = 20;
int *p = &i;
fun(p);
printf(\"i = %d\ \", i);
return 0;
}
3.
#include
void square(int);
main...


Slide Content

1.
void fun(int &j) {
j++;
}
int main() {
int i = 20;
fun(i);
printf(\"i = %d\ \", i);
return 0;
}
2.
void fun(int *j) {
(*j)++;
}
int main() {
int i = 20;
int *p = &i;
fun(p);
printf(\"i = %d\ \", i);
return 0;
}
3.
#include<stdio.h>
void square(int);
main() {
int num = 3;
square(num);
printf(“num: %d\ â€, num);
}
void square (int num) {
num = num * num;
}
4.
#include<stdio.h>
int square(int);
main() {
int num = 3;
square(num);
printf(“num: %d\ â€, num);
num = square(num);
printf(“num: %d\ â€, num);
}
int square (int num) {
num = num * num;
return num;
}

Solution
1)))))))))))))
the address of i is passed in the fuinction in this case
then in the function the address is incremented and print in the main block
2)))))))))))))))
p is a pointer as a pointer it stores the address of another variable
here p stores the address of variable i rather than the value of a variable
3))))))))))))))
function with arguement and no return type
the fun ction here declared as void so it doesnot return the value
4))))))))))
function with arguement and return type
it returns the value to the called function.
Tags