Answer the following questions in a text file (filename should be netid_lab1answ
ID: 3661973 • Letter: A
Question
Answer the following questions in a text file (filename should be netid_lab1answers.txt) and submit this file along with your hello.c program as an archive named netid_labw1 with the appropriate archive suffix (e.g., zip, tar, gz, rar)
Add the following variables to your hello.c C program
integer variable called myint
character variable called mychar
an integer pointer called myptr
Add code to your hello.c program to
Print out the "size" (in bytes) of each of these variables.
Print (out in decimal and hexadecimal) the largest decimal value that each of these can hold
1) do the values printed out for the largest decimal value make sense given the size (in bytes) of the variables?
Add one to each of the variables, and print out the resultant value in decimal and hexadecimal.
2) Can you explain why you get the values you do?
Do all of the above exercises again and add -m32 to your gcc command when compiling your hello.c
3) Do the results change? If so, why?
4) What is the difference between executing these two commands on bertvm:
./a.out vs. a.out
5) What are these commands attempting to do, you can assume they are being run on bertvm and that hello.c is a valid C program:
gcc -o hello.out hello.c -O2
gcc -S hello.c -O2
6) You compile your program hello.c on bertvm. Where can the executable that is produced be used? (you can see the executable in your mac finder, but can you "execute" the file on the mac?)
7) What are each of the following used for within your shell on a linux/unix machine?
|, >, <, &, fg, bg,
Explanation / Answer
1). Answer :
#include <stdio.h>
int main()
{
int myint;
char mychar;
int *myptr;
printf("Hello, World! ");
printf("size of integer : %d bytes ",sizeof(myint));
printf("size of character : %d byte ",sizeof(mychar));
printf("size of integer pointer : %d bytes ",sizeof(myptr));
return 0;
}
Output :
sh-4.3$ gcc -o hello *.c
sh-4.3$ hello
Hello, World!
size of integer : 4 bytes
size of character : 1 byte
size of integer pointer : 8 bytes
sh-4.3$
2) Answer :
#include <stdio.h>
int main()
{
int myint;
char mychar;
int *myptr;
myint=myint+1;
mychar=mychar+1;
myptr=myptr+1;
printf("Hello, World! ");
printf("size of integer : %d bytes ",sizeof(myint));
printf("size of character : %d byte ",sizeof(mychar));
printf("size of integer pointer : %d bytes ",sizeof(myptr));
return 0;
}
Output :
sh-4.3$ gcc -o hello *.c
sh-4.3$ hello
Hello, World!
size of integer : 4 bytes
size of character : 1 byte
size of integer pointer : 8 bytes
sh-4.3$
sh-4.3$ gcc -o hello *.c -m32
sh-4.3$ hello
Hello, World!
size of integer : 4 bytes
size of character : 1 byte
size of integer pointer : 4 bytes
sh-4.3$
3 ) Answer :
No change
Same output will give.
4) Answer :
When u type ./a.out that ./ tells the bash to look for the file a.out in the current directory .
If u type a.out in bash , without specifying the directory , it will search for it through directories in $ PATH variable .
5)
When these commands are run in terminal there is no change in output.
6) no answer
7)
fg : brings a stopped or background job to the foreground.
bg : sends a stopped job to the background.
& : use an ampersand at the end of the command to send the resulting job to the background immediately.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.