Questions 3
  1. How are arguments passed to functions in C: by-value or by-reference? And what does that mean?
    Hint: C syntax → argument passing.
  2. If double x=1.23, what is *(&x)? What is NULL? Hint: null pointer.
  3. What happens to variables declared inside a function when the function exits (returns)?
  4. What is a static variable? Hint: static variable.
  5. What will the following three programs print out and why?
    #include<stdio.h>
    void f(int i){i=0;}
    int main(){
    	int i=1; f(i); printf("i=%i\n",i);
    	return 0; }
    
    #include<stdio.h>
    void f(int* i){*i=0;}
    int main(){
    	int i=1; f(&i); printf("i=%i\n",i);
    	return 0; }
    
    #include<stdio.h>
    void f(int* i){i=NULL;}
    int main(){
    	int i=1; f(&i); printf("i=%i\n",i);
    	return 0; }
    
  6. If you pass an array to a function with the signature void f(double a[]) – what is actually passed to the function:
    1. the copy of the array?
    2. the pointer to the first element?
    3. the copy of the pointer to the first element?
    4. something else?
    Hint: C syntax → argument passing → array parameters.
  7. When the function with the signature void f(double a[]) gets the array as parameter – can it figure out the size of the array?
  8. If you declare an array as int a[5]; and then try a[7]=1; what will happen? Hint: Segmentation fault / causes.
  9. If you declare an i) static, ii) variable-length, iii) dynamic array inside a function, can the function return it?
  10. What will the following C-program print?
    #include<stdio.h>
    int i=2; /* file scope */
    void f(){printf("i=%i\n",i);}
    int main(){
    	int i=1; /* function scope */
    	{
    		int i=0; /* block scope */
    		printf("i=%i\n",i);
    	}
    	printf("i=%i\n",i);
    	f();
    	return 0; }