Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C PROGRAM ONLY: Suppose that you are using getchar() and putchar() to write a C

ID: 3662987 • Letter: C

Question

C PROGRAM ONLY:

Suppose that you are using getchar() and putchar() to write a C program that copies from an input file to an output file, one character at a time. Should you copy the EOF character to the output file? Why or why not?

Write a function declaration (prototype) for a function magnitude() that takes a single argument of data type "integer" and returns an int. The function definition is NOT required, only the prototype.

Write a function declaration (prototype) for a function smallest() that takes two arguments of data type "double" and returns a double.

Write a function declaration (prototype) for the function prtbox() takes no arguments and returns nothing.

Why can an actual argument be any expression with an appropriate type of value, but a formal argument can only be a variable?

In your own words, describe what a pointer variable is and identify at least one way they are used in the C language.

Declare a pointer variable called "size" that is a pointer to an integer variable.

Declare a pointer variable called "water_termperature" that is a pointer to a float variable.

Explain in your own words what global variables are (provide example code) and explain how and why they might be used.

Why are global variables dangerous, and why should they be not be used whenever possible?

Explanation / Answer

Should you copy the EOF character to the output file? Why or why not?

No,you don't need to copy EOF character. we close the file and leave it to operating system and the compiler library system to work out the details of how it is handled.

Write a function declaration (prototype) for a function magnitude() that takes a single argument of data type "integer" and returns an int. The function definition is NOT required, only the prototype.

The main difference between function declartion and function definition is function declaration does not have any body.function defined any place in the program it is called function definition.At the time of function definition actual logic is implemented with in the functions.
below is the declaration:
int magnitude(int a,int b);

Write a function declaration (prototype) for a function smallest() that takes two arguments of data type "double" and returns a double.

#include <stdio.h>
double smallest(); //function declaration
int main(void)
{
   printf("%f ", smallest(100.0));
}
double smallest(double param) //function definition
{
   return 4 * param ;
}

Write a function declaration (prototype) for the function prtbox() takes no arguments and returns nothing.

#include<stdio.h>

void prtbox(); // Prototype Declaration
void main()
{
prtbox();
}

void prtbox()
{
    float area_box;
    float rad;

    printf(" Enter radius : ");
    scanf("%f",&rad);

    area_box = 3.14 * rad * rad ;

    printf("Area of box = %f",area_box);
}

explanation:
void prtbox(); --> function does not return a value.Here is nothing specified brackets this function does not take any argument.

Why can an actual argument be any expression with an appropriate type of value, but a formal argument can only be a variable?

The main difference between actual arguments are source of information,calling the programs pass actual arguments to called functions.
formal arguments means the called functions access the information using the corresponding formal arguments.


/*Below program demonstrate difference between actual and formal arguments */
#include <stdio.h>
int addTwoInt(int, int); /* the Prototype */
int main() /* TheMain function */
{
int n11 = 10, n22 = 20, sum11;

/* n11 and n22 are the actual arguments. They are the source of data. The Caller program it supplies the data to called function in the form of actual arguments. */
sum11 = addTwoInt(n11, n22); /* The function call */
   printf("The Sum of %d and %d is: %d ", n11, n22, sum11);
}

/* a11 and b11 are formal parameters.it receive values fromthe actual arguments when this the function is called. */
int addTwoInt(int a11, int b11)
{
return (a11 + b11);
}

Output
======
The Sum of 10 and 20 is: 30

In your own words, describe what a pointer variable is and identify at least one way they are used in the C language.

A pointer variable is a typed name (it used at compile time only) and the run-time instance of necessary memory to hold the physical representation of a memory ofaddress an appropriate type.pointer variable used for arrays and it allow functions to modify the values in the calling routine and matrices.

Declare a pointer variable called "size" that is a pointer to an integer variable.

int * size;

Declare a pointer variable called "water_termperature" that is a pointer to a float variable.

float * water_temperature;

Explain in your own words what global variables are (provide example code) and explain how and why they might be used.

global variables is variable it can access throughout the program and the changes are made to global variable persist.But local variable declaration within the block only.
Once you declare global variable no need to declare again when we use anywhere that variable.

example:
int x=0;
    int main()
    {
        int y=0; //it can be used within main()
        return 1;
    }

    int dis()
    {
        x=5; //it Can be accessed in any functions and it made changes to it
    }

Why are global variables dangerous, and why should they be not be used whenever possible?

When we declare too many variables as global , then it remain in the memory till the program execution is over
An Unprotected data