In: Computer Science
What is the difference between the two statements below? In addition, in what folders (general not specific) would the below files be located?
#include <string.h>
#include “myHeader.h”
Write an example of a post-test while loop
Describe the difference between pass by pointer (reference) and pass by value? Which one executes faster? Which one takes more memory space? Which one can modify the original data set being passed? (note 4 sub-questions)
(1.) The difference between #include<myHeader.h> and #include "myHeader.h" are as follows:-
#include<myHeader.h> is used for predefined standard header files, where as #include "myHeader.h" is used for used defined header files, #include "myHeader.h" is used for header files in current directory, and the compiler searches the current directory for the header file, where as the #include<myHeader.h> is used for standard directory searches of header files.
(2.) The example of post-test while loop is as follows:-
#include<stdio.h>
int main()
{
int i=1;
do
{
printf("%d ",i);
i++;
}while(i<10);
return 0;
}
Output :- 1 2 3 4 5 6 7 8 9
(3.) The difference between call be value and call by reference is as follows:-
Call by value | Call by reference |
While calling a function, the copy of variable is passed | While calling a function, the address of the variable is passed |
Change made in copy of variable will not modify the actual value of variable in outside the function | Change made in the variable will also modify the actual value of variable in outside the function |
Actual and formal arguments will be located at different memory location | Actual and formal arguments will be located at same memory location |
Value is passed simply | Value is passed through pointers. |
It is slower in execution | It is faster in execution |
It can take more memory space if it used data type of larger size | It can take less memory space as the pointer size is always fixed |
It can not modify the original data set being passed | It can modify the original data set being passed |