Question

In: Electrical Engineering

this program is to be done in c language. Using Pointers Create a program pointerTester.c to...

this program is to be done in c language. Using Pointers Create a program pointerTester.c to experiment with pointers. Implement the following steps one by one in your program: YOU NEED TO ANSWER QUESTION Use printf to print your answers at the end(after 12). 1. Declare three integer variables a, b and c. Initialize them to 0, 100 and 225, respectively. 2. Print the value of each variable and its address. 3. Add the following declaration to your code: int *pA = &a, *pB = &b, *p; 4. Print the value of each pointer and the value it points to (using the pointer) 5. Run your program multiple times. a. Does any of the values *pA, *pB or *p change? b. Does any of the values pA, pB or p change? 6. Change the value that p points to to 50 without declaring the valuable that p points to. Can you print the value that p points to? 7. Declare an array z of 10 integers and initialize its elements to 0, 1, 2, …., 9 8. Print the address of each element in the array using the z[i] notation 9. Print the address of each element in the array using the z + i notation 10. Print the content of the array using z + i notation 11. Declare a string literal x and set it to value “hello”. 12. Change the second character of x to upper case. What happens? Strings Write a program reading.c that reads from standard input according to the user’s choice. The program should ask “How would you like to read?” 1: character by character; 2: word by word; 3: line by line. Default: print “Invalid choice”. You should write the three procedures below. - The procedure readCharByChar asks the user to enter 5 characters and read them (hint: using %c). - The procedure readWordByWord asks the user to enter 5 words and read them (hint: using %s). - The procedure readLineByLine should ask the user to enter 5 lines and read them (hint: using gets). In each of the three procedures, the values read should be printed to the screen, each on a separate line showing: input index, tab, unit (char, word, or line). According to the user choice, your program uses a switch statement to call readCharByChar, readWordByWord, and readLineByLine, respectively. Make sure your code is properly indented, your variables have meaningful names, and macro definitions are used when appropriate.

Solutions

Expert Solution

Refer to the given problem.

Consider the following c language program.

C program:

#include <stdio.h>
int main()
{
// 1. Declaring a, b and c ( integer variables). Now initializing the integer to 0, 100 and 225, respectively.
int a,b,c;
a = 0;
b = 100;
c = 225;

// 2. Printing each variable value a,b and c and its address
printf("Variable a = %d and addrress is %u\n", a,&a);
printf("Variable b = %d and addrress is %u\n", b,&b);
printf("Variable c = %d and addrress is %u\n", c,&c);

// 3. Adding declaration to the code:
//int *pA = &a, *pB = &b, *p;
int *pA = &a, *pB = &b, *p;

// 4. Printing each pointer value which it points to (via pointer)
printf("Value of pointer pA = %u and value it points to %d\n", pA, *pA);
printf("Value of pointer pB = %u and value it points to %d\n", pB, *pB);
printf("Value of pointer p = %u and value it points to nothing\n", p);
// The value and address of For pA and pB gets printed but for pointer p, nothing points thus it’s a null pointer
//printf("Value of pointer p = %u and value 1it points to %d\n", p, *p) // will not work and error is fault segmentation;

// 5. Start running the program for multiple times.
// 5.a. Check if any of the values *pA, *pB or *p alter?
// >>>> By running program multiple times *pA *pB does not changes
// 5.b. check if any of the values pA, pB or p alter?
// >>>> By running program multiple times pA pB changes but p remains to 0

// 6. Update the value of p.
*p = 50;//Print the value of p.
printf("Value of pointer p = %u and value it points to %d\n\n", p, *p);

// 7. Declare an array
int z[10];//Initialize the aaray
for(int i = 0 ; i < 10 ; i++)
{
z[10] = i;}

// 8. Iterate through the array and print the value.
for(int i = 0 ; i < 10 ; i++)
{
printf("value of z[%d] = %d\n",i ,i);
z[10] = i;}

// 9. Iterate through the array and print the address.
for(int i = 0 ; i < 10 ; i++)
{
printf("address of z[%d] = %u\n",i ,z+i);
z[10] = i;
}

// 10. Iterate through the array and print using z + i notation
for(int i = 0 ; i < 10 ; i++)
{
printf("content of z + %d = %d\n",i ,*(z+i));
z[10] = i;}

// 11. Define the string variable.
char *x = "hello";

// 12 . Update the variable change 2nd index to uppercase.
printf("%c", *(++x)-32);return 0;}

Consider the following Output:

Output:

Hope it helps!


Related Solutions

Done in C language using mobaxterm if you can but use basic C This program is...
Done in C language using mobaxterm if you can but use basic C This program is broken up into three different functions of insert, delete, and main. This program implements a queue of individual characters in a circular list using only a single pointer to the circular list; separate pointers to the front and rear elements of the queue are not used. The linked list must be circular.      The insert and remove operations must both be O(1)    You...
Using C++ language, create a program that uses a struct with array variables that will loop...
Using C++ language, create a program that uses a struct with array variables that will loop at least 3 times and get the below information: First Name Last Name Job Title Employee Number Hours Worked Hourly Wage Number of Deductions Claimed Then, determine if the person is entitled to overtime and gross pay. Afterwards, determine the tax and net pay. Output everything to the screen. Use functions wherever possible. Bonus Points: Use an input file to read in an unknown...
The concept of pointers in C++ is inherited from the C language, which relies extensively on the use of pointers.
  Topic: The concept of pointers in C++ is inherited from the C language, which relies extensively on the use of pointers. What are the advantages and disadvantages of having the functionality of pointers in a programming language?
How do I create this program? Using C++ language! Write a program that reads data from...
How do I create this program? Using C++ language! Write a program that reads data from a text file. Include in this program functions that calculate the mean and the standard deviation. Make sure that the only global varibles are the mean, standard deviation, and the number of data entered. All other varibles must be local to the function. At the top of the program make sure you use functional prototypes instead of writing each function before the main function....ALL...
Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
MUST BE DONE IN C (NOT C++) Your create a program that can implement the cases...
MUST BE DONE IN C (NOT C++) Your create a program that can implement the cases in which the initial unit is Fahrenheit or something not recognizable. Your program should incorporate Fahrenheit to Celsius, Fahrenheit to Kelvin and unknown initial units (display an error message for this last one). You must use functions to calculate Fahrenheit degrees.
Write a complete C program that searches an element in array using pointers. Please use the...
Write a complete C program that searches an element in array using pointers. Please use the function called search to find the given number. //Function Prototype void search (int * array, int num, int size)
Write a C++ program (using pointers and dynamic memory allocation only) to implement the following functions...
Write a C++ program (using pointers and dynamic memory allocation only) to implement the following functions and call it from the main function. (1)Write a function whose signature looks like (char*, char) which returns true if the 1st parameter cstring contains the 2nd parameter char, or false otherwise. (2)Create an array of Planets. Populate the array and print the contents of the array using the pointer notation instead of the subscripts.
C language Write a program in C to implement Queue and its operation (like create, insert,...
C language Write a program in C to implement Queue and its operation (like create, insert, delete, search) using array data structure.
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create 2 threads that will act as counters. One thread should count down from 5 to 0. Once that thread reaches 0, then a second thread should be used to count up to 20.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT