Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4.0 PROCEDURE Section 1: Pointer Operator & Running C Program in Command Prompt 1. Open your preferred C++IDE, and create new file called pointer.c. Save

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
4.0 PROCEDURE Section 1: Pointer Operator \& Running C Program in Command Prompt 1. Open your preferred C++IDE, and create new file called "pointer.c". Save your project at the Desktop. 2. Type the following program code: tinclude icotdio, hy lntman(y) int "ptr_a, "ptr_b; tin num_ e=4, hum_d =7 t pet_a - isum_et pez_b - pta_a: per b - inum_ 4t "ptr_a =iptr_bi retarn of 3. Compile and run your program and observe the output of the program. 4. Explain briefly, what happen in the program at line 817. 5. Modify the program so that it displays the address of the variable "num_c" and "num d ". 6. Copy and paste your program code and submit it with your lab report. 7. Now, open your Command Prompt. Section 2: Dynamic Data 1. Write a program to find the maximum number between two numbers using pointer You can do this in three steps: a) Declare a pointer and variable: int tno,sno, "ptr1=sfno, "ptr2=5sno: b) Input your numbers c) Finally, use pointer to do the comparison and display the output Sample cutput: Pointer: Find the maximum number between two numbers : Input the first number : 2 Input the second number : 3 3 is the maximum number. Section 3: Pointer Application 1. Open your preferred C IDE, and create new console project. 2. Type the following program: F demonstrate calling functions by value, by pointers, and by references % include f add two numbers together and retum the result int add (int x, int y ) i // Add Your Code Here i take two pointer references to integers and swap their values i.e. if x=5 and 7y=3 before the call to swap then after x=3 and y=51 void swap (int * x, int *y) 1 int temp: // Add Code Here 1 It takes one integer by reference and decrements the value pointed to by x% int dec(int *x) 1 "Add Your Code Here ) 2 I* takes one integer by reference and increments the value pointed to by x/ int inc (int * x ) i // Add Your Code Here \} int main() i int num1, num2; int result1; int result2; printf("Enter two numbers separated by a space " ); scanf ("sod sd", \&num1, \&num2); printf("num1 is 8d, num2 is 8d ", num1, num2); // Add Your Code Here \} 3. Alter and complete the rest of the code to test the add, swap, decrement, and increment functions and display each result before and after each function call to validate the code. Then compile and run the code. a. Explaination of line 8-17 of the program

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions