XCode - C Program 1. Write one line of code to printout the memory address (in h
ID: 3909370 • Letter: X
Question
XCode - C Program
1. Write one line of code to printout the memory address (in hex) of the 0'th element of the integer vector ivec[ ] below.
int ivec[3 ]={1,2,3};
2.Rewrite the following statements using the conditional operator ? rather than if-else logic.
if (a != b){ x = a;}
else{x = c;}
3.Write a single statement, using the file-pointer below, to open up a file for reading called "myfile.txt". The file resides in the folder "myfolder" on the C: drive of the computer. Your program will be run from the base directory of the D: drive of the computer.
FILE *fp;
4. Write a single statement below to print the memory address (in decimal) where the integer variable ix is stored in the computer's memory. int ix=1.0;
5. Write two statements below. The 1st statement will read in a word from the keyboard and store it in the character array v[100]. The 2nd statement will printout the number of characters in the word. char v[100]; printf("Please enter a word ");
6. Write a function definition for a subroutine that receives a float variable x and returns an integer variable ix where ix is the value of x rounded to the nearest integer. The subroutine should work correctly for both positive and negative values of float variable x.
Explanation / Answer
1)
printf("The memory address = 0x%p",(void *)ivec);
2)
x = (a!=b?a:c);
3)
fp = fopen("..\..\C:\myfile.txt", "r");
4)
printf("The memory address = 0x%p",(void *)&ix);
5)
scanf("%s", v);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.