Question

Let us discuss the following code and determine the outoput. #include <stdio.h> int main() { int...

Let us discuss the following code and determine the outoput.

#include <stdio.h>

int main()
{
int a=10; //normal variable
int *ptr_a; //pointer variable


ptr_a = &a;

int **ptr_ptra; //pointer to pointer

ptr_ptra = &ptr_a;

printf("value of a: %d\n",a);
printf("value of a using pointer: %d\n",*ptr_a);
printf("value of a using pointer to pointer: %d\n",**ptr_ptra);

return 0;
}

Homework Answers

Answer #1
#include<iostream>
#include <iomanip>
using namespace std;

#include <stdio.h>

int main()
{
int a=10; //normal variable
int *ptr_a; //pointer variable


ptr_a = &a;
// ptr_a is pointing to memory location of a
// *ptr_a is used to get the value at address a

int **ptr_ptra; //pointer to pointer

ptr_ptra = &ptr_a;
// ptr_ptra points to memory location of ptr_a
// *ptr_ptra is used to get the value at address ptr_a
// **ptr_ptra is used to get the value at address a

printf("value of a: %d\n",a);
printf("value of a using pointer: %d\n",*ptr_a);
printf("value of a using pointer to pointer: %d\n",**ptr_ptra);

return 0;
}



value of a: 10
value of a using pointer: 10
value of a using pointer to pointer: 10


Know the answer?
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
Similar Questions
could someone please explain this code and the output to me? #include <stdio.h> #include <unistd.h> int...
could someone please explain this code and the output to me? #include <stdio.h> #include <unistd.h> int main(void) { printf("one\n"); fork(); printf("two\n"); return 0; }
What is output? #include <stdio.h> void CheckValue(int* pointVar1, int* pointVar2) {       if (pointVar1 == NULL...
What is output? #include <stdio.h> void CheckValue(int* pointVar1, int* pointVar2) {       if (pointVar1 == NULL && pointVar2 == NULL) {       printf("Pointer is null\n");    }    else if (*pointVar2 > *pointVar1) {       printf("%p\n", *pointVar2);    }    else if (*pointVar1 > *pointVar2) {       printf("%p\n", *pointVar1);    } } int main() {    int num1 = 5;    int num2 = 9;       CheckValue(&num1, &num2);           return 0; } a. 0 b. 5 c. 9 d. Pointer is null e....
What would appear in the console window after the code below executes? #include <stdio.h> int main()...
What would appear in the console window after the code below executes? #include <stdio.h> int main() { char myLetter = 'A'; printf("The value of A is %d", myLetter); }
Considering the following code fragment: #include<stdio.h> #include <stdlib.h> int base = 0; static int bonus; int*...
Considering the following code fragment: #include<stdio.h> #include <stdlib.h> int base = 0; static int bonus; int* demage (int dmg) { int* ptr = (int*) malloc(sizeof(int)); static int constant = 1;   *ptr = dmg + constant; return ptr; } int main() { int HP = 0; int* dm; base = 30; bonus = 20; for(int i=1; i<4; i++) { HP += i * base; } dm = demage(10); HP += bonus - *dm; printf("Total HP: %i", HP); return 0; } Please...
#include<stdio.h> int main() {       /* For binary search, the array should be arranged in ascending...
#include<stdio.h> int main() {       /* For binary search, the array should be arranged in ascending or descending order */       int data[] = {1,2,3,4,5,6,7,8,9,10}; ****You might change the numbers for your program also       /* 'min' use for starting location of the array, 'max' use for end location of the array and 'mid' use for middle location of the array */       int min = 0, max = 10, search, mid = (max + min) / 2;       printf("Enter...
Using the following code answer the next couple questions: #include<stdio.h> #include<stdlib.h> #include<string.h> /* Rewrite using a...
Using the following code answer the next couple questions: #include<stdio.h> #include<stdlib.h> #include<string.h> /* Rewrite using a pointer to char str[] */ void array_to_ptr () { int n=0, len; char str[ ] = "Hello World!"; len = strlen(str); for( n=0; n<len; n++) {     putc(str[n], stdout); } printf("\nlength = %d\n", n); } int contains (char * str, char c); int * makearray(int n); int main (void) { printf("Question #2 - array_to_ptr:\n"); array_to_ptr();   printf("\n------------------------------------\n\n"); printf("Question #3 - contains:\n"); printf("Test #1: "); if...
Construct a flowchart based on this code and write its equivalent algorithms. #include <stdio.h> int main()...
Construct a flowchart based on this code and write its equivalent algorithms. #include <stdio.h> int main() { int x,y; float result; char ch; //to store operator choice printf("Enter first number: "); scanf("%d",&x); printf("Enter second number: "); scanf("%d",&y); printf("Choose operation to perform (+,-,*,/): "); scanf(" %c",&ch); result=0; switch(ch) { case '+': result=x+y; break; case '-': result=x-y; break; case '*': result=x*y; break; case '/': result=(float)x/(float)y; break; case '%': result=x%y; break; default: printf("Invalid operation.\n"); } printf("Result: %d %c %d = %.2f\n",x,ch,y,result); // Directly...
Here is my code: //preprocessor files #include <stdio.h> #include <stdlib.h> void printScores(float scores[]); int main() {...
Here is my code: //preprocessor files #include <stdio.h> #include <stdlib.h> void printScores(float scores[]); int main() {    char s_name[] = "ECPI University";    float scores[6] = {78.7, 98.4, 100.0, 96.5, 100.0, 88.8};    float average = 0.0;    int counter;       printScores(scores);       for(counter = 0; counter < 6; counter++){        average += scores[counter];    }         average /= float(6); ===============this is where i am getting the error          printf("\nAt %s, your class average...
don't understand why this code outputs 3. Why doesn't it output 32?? #include <stdio.h> #include <ctype.h>...
don't understand why this code outputs 3. Why doesn't it output 32?? #include <stdio.h> #include <ctype.h> int main() { printf("%d\n", parseint("32")); return 0; } int parseint(char *str) { int i=0; while(str[i] != '\0'){ return (str[i] - '0'); i++; } return 1;    }
2. Calculate number of times hello is printed. #include <stdio.h> #include <sys/types.h> int main() { fork();...
2. Calculate number of times hello is printed. #include <stdio.h> #include <sys/types.h> int main() { fork(); fork(); fork(); printf("hello\n"); return 0; }
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT