Lab2: Static Variables and Error Reporting Complete the following tasks and show its execution for different inputs. In your lab report, show the program code and execution. Show execution using a transcript or screenshots.
Task 1: Write a C program that prints errorno when the user tries to open a write protected file. Also print the descriptive error using perror(). Task 2: In a C program try to close a file that was never opened. Show the errorno and error message that it generates. Task 3: What would be the output of the following program? Please explain? #include <stdio.h> void getPrint() { int var = 0; static int staticVar = 0; var += 10; staticVar += 10; printf("var = %d, staticVar = %d\n", var, staticVar); } int main() { int i; for (i = 0; i < 10; ++i) getPrint(); }
Task 4: What is the difference between a static and non static global variables.