SE 314 Lab-4 Advanced C-programming
SE 314 Lab-4 Advanced C-programming
Fall 2023
Objectives:
}
/*Print result */
printf("The world %s has %d characters .\n",argv[1],n);
}
Run the code by typing: ex1 YourName in terminal and attache screen shot of the output of
this code in the space provided.
Screen Shot:
3- If I run the program using: ex1 Ahmed, what is will be the values inside argc
and argv?
Exercise 1: Write a C program that does simple mathematical operations (+
- / *) when run in the terminal as follows:
>myCalc 3 + 4
>7
> myCalc 3 * 4
>12
Include a copy of your code here:
Attache screen shot of the output of this code in the space provided.
Screen Shot:
Pointer Syntax
Here is how we can declare pointers in any of the following ways:
int* p;
int *p1;
int * p2;
Then, we changed the value of c to 1. Since pc and the address of c is the same, *pc
gives us 1.
Then, we changed *pc to 1 using *pc = 1;. Since pc and the address of c is the
same, c will be equal to 1.
Save the following code, compile, and run it
#include <stdio.h>
int main()
{
int* pc, c;
c = 22;
printf("Address of c: %p\n", &c);
printf("Value of c: %d\n\n", c); // 22
pc = &c;
printf("Address of pointer pc: %p\n", pc);
printf("Content of pointer pc: %d\n\n", *pc); // 22
c = 11;
printf("Address of pointer pc: %p\n", pc);
printf("Content of pointer pc: %d\n\n", *pc); // 11
*pc = 2;
printf("Address of c: %p\n", &c);
printf("Value of c: %d\n\n", c); // 2
return 0;
}
Attache screen shot of the output of this code in the space provided.
Screen Shot: