Question

Look at the following code and comment each line about how it works with pointer. int...

  1. Look at the following code and comment each line about how it works with pointer.

int i = 33;

double d = 12.88;

int * iPtr = &i;   

double * dPtr = &d; //

iPtr = &d;   //

dPtr = &i;   //

iPtr = i;    //

int j = 99;

iPtr = &j; //

0 0
Add a comment Improve this question Transcribed image text
Answer #1

int i = 33; // An int variable with a value

double d = 12.88;  // An double variable with a value

int * iPtr = &i;   // Declared a pointer variable called iPtr pointing to an int (or int pointer) and Assign the address of the variable number to pointer iPtr

double * dPtr = &d; // Declared a pointer variable called dPtr pointing to an double (or double pointer)

// Assign the address of the variable number to pointer dPtr

iPtr = &d;   //Assign the address of the variable number to pointer iPtr

dPtr = &i; //Assign the address of the variable number to pointer dPtr

iPtr = i;    //Assign variable number to pointer iPtr

int j = 99;//declared j int variable

iPtr = &j; // assign the address of variable to pointer iPtr

Add a comment
Know the answer?
Add Answer to:
Look at the following code and comment each line about how it works with pointer. int...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • [C++ Language] Look at the following code and comment each line about how it works with...

    [C++ Language] Look at the following code and comment each line about how it works with pointer. int i = 33; double d = 12.88; int * iPtr = &i;    double * dPtr = &d; // iPtr = &d;   // dPtr = &i;   // iPtr = i;    // int j = 99; iPtr = &j; //

  • The following code snippet is for C++ int selection_Sort(int A[ ], int n) { int I,...

    The following code snippet is for C++ int selection_Sort(int A[ ], int n) { int I, j, small, temp; for( i = 0; i < n-1; i++) { small = i; for(j = i + 1; j < n; j++) { if ( A[ j ] < A[ small ] small = j; } temp = A [ i ]; A[ i ] = A[small]; A[small] = temp; } } Please explain in rich detail the logic behind every execution...

  • Given the following Java code: class C { public int foo(C p) { return 1; }...

    Given the following Java code: class C { public int foo(C p) { return 1; } } class D extends C { public int foo(C p) { return 2; } public int foo(D p) { return 3; } } C p = new C(); C q = new D(); D r = new D(); int i = p.foo(r); int j = q.foo(q); int k = q.foo(r); (Remember that in Java every object is accessed through a pointer and that methods...

  • Translate the following code into MIPS code. Test (int i, int j)                         {        &nbsp

    Translate the following code into MIPS code. Test (int i, int j)                         {                         int k;                         k = Double(i+1) + Double (j-10)                         return k;                         } Sub (int m)                         {                         int g;                         g = m + m;                         return g;                         } Assume the compiler associates the variable k to the register $s0. Assume the compiler associates the variable g to the register $t0.

  • Question 2 (a) Provide a single line of C++ code that will declare a variable that...

    Question 2 (a) Provide a single line of C++ code that will declare a variable that points to a string value, the variable is named x. [2 marks] (b) You have array c declared as string *c [5]; Give the single line of C+ + code that will assign the string pointer stored in variable x (from above) to the third element of the array c. [2 marks] (c) Write a for loop that initialises the contents of each element...

  • The following lines of code all have problems. Identify what is wrong with each line of...

    The following lines of code all have problems. Identify what is wrong with each line of code The following lines of code all have problems. Identify what is wrong with each line of code. a) for(j=0; j<= 10; j++) cout << prices[j]; b) int array = {1,2,3,4}; c) int arr[3]; for (arr = 0; arr < = 10; arr++) d) char k; for (k=0; k<= 10; k++)

  • Show how to get the big-Oh for the following code: void CountSort (int A[N], int range)...

    Show how to get the big-Oh for the following code: void CountSort (int A[N], int range) { // assume 0 <= A[i] < range for any element A[i] int *pi = new int[range]; for ( int i = 0; i < N; i++ ) pi[A[i]]++; for ( int j = 0; j < range; j++ ) for ( int k = 1; k <= pi[j]; k++ ) cout << j << endl; }

  • Please explain how these code run for each line #include<stdio.h> #include<string.h> /** * Part A */...

    Please explain how these code run for each line #include<stdio.h> #include<string.h> /** * Part A */ struct myWord{    char Word[21];    int Length; }; int tokenizeLine(char line[], struct myWord wordList[]); void printList(struct myWord wordList[], int size); void sortList(struct myWord wordList[], int size); /** * main function */ int main() {    struct myWord wordList[20];    char line[100];    printf("Enter an English Sentence:\n");    gets(line);    int size = tokenizeLine(line, wordList);    printf("\n");    printf("Unsorted word list.\n");    printList(wordList, size);...

  • 7. The code segment given sorts an array. Show how this works on the given array...

    7. The code segment given sorts an array. Show how this works on the given array by redrawing the array each time one of the entries changes value. const int IsizeĀ·6; // list size int list [lsize]; int j, x; for (int i = !size-1; i > 0; i-) { x = list [i]; ji; for (int k = i-1 ; k >= 0; k-) { if (list [k] > x) f j -k; x = list(k); list [j] list...

  • Explain the following code, line by line. As well as the is going on over all....

    Explain the following code, line by line. As well as the is going on over all. #include <stdio.h> int main() {   int a[30];   int i,j,lasti;   int num;      lasti=0;   // scanf the number   scanf("%d",&a[0]);   while (1)   {   // sacnf the new number   printf("Enter another Number \n");   scanf("%d",&num);   for(i=0;i<=lasti;i=i+1)   {   printf("%d \n",a[i]);   // we check if the num that we eneterd is greter than i   if(a[i] > num)   {   for(j=lasti; j>= i;j--)   {   a[j+1]=a[j];   }      a[i]=num;   lasti++;   break;   }   }...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT