0
What are test(i) and void in this c program
#include <stdio.h> void test(int k); int main() { int i = 0; printf("The address of i is %x\n", &i); test(i); printf("The address of i is %x\n", &i); test(i); return 0; } void test(int k) { printf("The address of k is %x\n", &k); } Can anyone please explain what is test(i), why we used void and also why we used & in print statement
2 Antworten
0
1. test(i)
here, test is a user defined function which takes an argument i..Functions are a piece of code that is needed in program more than 1 time..so instead of writing that code agaim and again..we simply call a function..whenever the compiler will reach test(i) its control will jump to definition of test function and will execute code present in function..after executing function's code it will come back to the line from where it jumped...
2. Void
Void is a return type..It means that what value will function return. Here test function is just printing address of variable k and is not returning any value so it is defined as void..In simple terms, Void means 'nothing'..
3.The reason behind using & in print statement is to print address of variable..Whenever you use & in C it means you are dealing with address..Address is simply memory location in which variable is stored..
I hope you understood this..As i can see from your question that you are new here..You will come to know about this in C tutorials..
0
Thankyou