/*
Codes for exercise on data types, and function
parameters. / Answer the Table below by analyzing/ modifying the
code
*/
#include <stdio.h>
#include <string.h>
typedef char String[11];
/*
Lines 29 to 39 are called "function prototypes"
or "function declarations". A function prototype only
contains
the functions's return type, function name and
formal parameters.
Your task is to replace the blank (underline)
with appropriate data type for the formal parameter named
param.
When you are done encoding your answer, go to
the command line, and compile the program
NOTES: the -c is a compiler option which will
compile only (but not link) the C program. There should NOT
be any compilation
error or warning! If
there is an error or warning, then there is something wrong
somewhere. Fix your codes.
If there is no error,
a new file will be produced. This is an object
file.
Do NOT run the
program because it is not a stand-alone exe file!
*/
void Zero( ___ param ); // answer: char * (or char*)
void One( ___ param );
void Two( ___ param );
void Three( ___ param );
void Four( ___ param, char *str );
void Five( ___ param );
void Six( ___ param );
void Seven( ___ param );
void Eight( ___ param );
void Nine( ___ param );
void Ten( ___ param );
int
main()
{
/* Do NOT change any of the
declarations/definitions below. */
char str[11];
// Assume that &str[0] is FE30.
char S[11] = "ABCDEVWXYZ";
// Assume that &S[0]
is FE20.
int A[10] = {1, 3, 5, 2, 4, 9, 8, 6, 7};
// Assume that &A[0] is FDF0.
double M[2][3] = { {1.1, 8.8, -5.5}, {-3.3, 7.7}
}; // Assume that &M[0][0]
is FDC0.
String L[5] = { "Hello!", "How", "are", "you?"};
// Assume that
&L[0] is FD80.
String Z[2][5] = { {"NEKO", "INU", "USAGI",
"TORA", "KUMA"}, // Assume that &Z[0][0] is FD10.
{"CAT", "DOG", "DEER", "TIGER", "BEAR"}
};
strcpy(str, L[0]); // do not change this
strcpy().
/*
The following are
function calls. You need to answer two questions in the
Canvas Quiz for each function call:
Q1: What is the value of the
parameter?
Q2: What is the data type of the
parameter?
For example, for function
call Zero(str+2): FE32 is the value of the parameter, and char * is
its data type.
Explanation: recall from our
recent lecture that acdg to K&R: the name of the array is
snynonymous with the
location (i.e., memory address) of the initial
element (i.e., 1st element).
Based on the given comment in
Line 46: str is synonymous with &str[0] which is assumed above
to be address FE30.
Thus, str + 2 is equal to
FE30 + 2 = FE32.
*/
Zero(str+2);
// Q0 FE32 char
*
One(&A[9]);
Two(S[7]);
Three(*(&A[5]+1));
Four(strcpy(L[4], "Bye!"), "Hello");
Five(*(S+A[5]));
Six(M[1][2]);
Seven(&M[1][2]);
Eight(&L[2][1]);
Nine(Z[1][3]);
Ten(M[1]);
return 0;
}
Answer this table below
. Encoding Rules: Make sure that you follow the encoding rules below because Canvas performs a limited strict string matching with the Answer Keys. If you do not comply, your answer will be marked automatically by Canvas as incorrect. Please take note that I will not manually override the score in case of non-compliance. . The data type must be written the way it is written in C language. For example, you should type int (not integer). • A char value may be encoded with or without a pair of single quotes. • A double value must be encoded with EXACTLY TWO digits after the decimal point • A pointer (i.e., memory address) value must be encoded as a HEXADECIMAL number -- specify 4 digits only, for example F1A2. • A pointer data type should have either zero or at most one space preceding the asterisk. For example, encode a character pointer data type as either char* (zero space) or char * (one space). • Do NOT use square brackets (array notation) in your answer for the formal parameter data type. • Do NOT use the typedef alias name in your answer for the formal parameter data type. Formal Parameter Data Function Parameter Value Type Zerol) . FE32 char Onel int Two char Three char Four) char Fivel) Six) Seven() Eight) Ninel Teno
/* Codes for exercise on data types, and function parameters. / Answer the Table below by analyzing/ modifying the co
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
/* Codes for exercise on data types, and function parameters. / Answer the Table below by analyzing/ modifying the co
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!