Can I get help answering these questions and some explanation so I can understan
ID: 3720007 • Letter: C
Question
Can I get help answering these questions and some explanation so I can understand them? The language for this is C programming.
CS1325 1. 2. 3. 4. What pieces of information does C need before it can execute a function call? If we want to include our own header files in a program, what syntax do we use? What is the difference between scope and duration? Let's run through the scope, duration, and initialization rules for global, local, static oca Scope Duration Init Global Local Static Local 5. 6. 7. 8. What data type do we create a pointer to when we open a file? What is the name of the function that opens a file? What are the arguments? How can we tell if a file has been opened correctly? What mode for: a. opening for input and output, orig data not erased, file position pointer at beg b. opening for input and output, orig data are erased, file position pointer at beg c. opening for input and output, orig data not erased, file position pointer at end, all writes to end 9. fgets0 function What are the arguments for the fgets) function? Does it null terminate? How many characters read? a. b. 10. fputs) function a. Arguments? Does it append a newline? 11. Return value for the fscanf) function. 12. Let's say we have a pointer pointing into an array of doubles (8 bytes per element) and it is pointing at memory address 5000. We add 2 to the pointer. What address is it now pointing to? 13. Say we haveExplanation / Answer
1)Answer:
a function is a module of code that takes information in (referring to that information with local symbolic names called parameters), does some computation, and (usually) returns a ... When a line of code in a function that says: "return X;" is executed, the function "ends" and no more code in the function is executed.
2)Answer:
.h extension are called header files in C. These header files generally contain function declarations which we can be used in our main C program, like for e.g. there is need to include stdio.h in our C program to use function printf() in the program. So the question arises, is it possible to create your own header file? The answer to the above is yes. header files are simply files in which you can declare your own functions that you can use in your main program or these can be used while writing large C programs.
Below is the short example of creating your own header file and using it accordingly.
// It is not recommended to put function definitions
// in a header file. Ideally there should be only
// function declarations. Purpose of this code is
// to only demonstrate working of header files.
void add(int a, int b)
{
printf("Added value=%d ", a + b);
}
void multiply(int a, int b)
{
printf("Multiplied value=%d ", a * b);
}
// C program to use the above created header file
#include <stdio.h>
#include "myhead.h"
int main()
{
add(4, 6);
/*This calls add function written in myhead.h
and therefore no compilation error.*/
multiply(5, 5);
// Same for the multiply function in myhead.h
printf("BYE!See you Soon");
return 0;
}
Output:
3)Answer:
Life Time – Life time of any variable is the time for which the particular variable outlives in memory during running of the program.
It is the duration of time for which the variable holds the value during the execution of a program. For local variable the lifetime is within the functional block in which it is declared. The memory allocated when function starts and deallocated when it terminates. So,the lifetime of the variable defined in that block is local the functional block.
Scope – The scope of any variable is actually a subset of life time. A variable may be in the memory but may not be accessible though. So, the area of our program where we can actually access our entity (variable in this case) is the scope of that variable.
The scope of any variable can be broadly categorized into three categories :
It defines the visibility/accessibility of the variable in a program. For example take a local variable where the scope is local to that function.For static global variable,scope is limited to that file only. For global variable the scope is across multiple files (if it is with extern specifier)
// It is not recommended to put function definitions
// in a header file. Ideally there should be only
// function declarations. Purpose of this code is
// to only demonstrate working of header files.
void add(int a, int b)
{
printf("Added value=%d ", a + b);
}
void multiply(int a, int b)
{
printf("Multiplied value=%d ", a * b);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.