Question

C PROGRAMMING LANGUAGE The following code written in C programming language was run and displays 997705320....

C PROGRAMMING LANGUAGE

The following code written in C programming language was run and displays 997705320. Explain why and how this program outputs this number.

int main(void) {

int a = 5, b =20;

int* ptr = &a;

int** ptr2 = &ptr;

printf("%d\n", ((int)*ptr * (int)*ptr2));

return 0;

}

Homework Answers

Answer #1

The program :

int main(void) {

int a = 5, b =20;

int* ptr = &a;

int** ptr2 = &ptr;

printf("%d\n", ((int)*ptr * (int)*ptr2));

return 0;

}

EXPLANATION :

Here , ptr is the pointer that is pointing to the variable a . And **ptr2 is the double pointer which stores the address of pointer variable ptr.

And at each time when this code runs , the memory allocated to pointer ptr and ptr2 is different.

Hence when you runs this code, memory allocated to ptr is 199541064.

And so value of (int)*ptr is 5 as ptr is pointing to variable a. And the value of (int)*ptr2 is 199541064

printf("%d\n", ((int)*ptr * (int)*ptr2));

And the above statement will print : ( 5 * 199541064 ) = 997705320

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
FOR C PROGRAMMING LANGUAGE Which of the three C programming language functions are likely to cause...
FOR C PROGRAMMING LANGUAGE Which of the three C programming language functions are likely to cause problems in a program that calls them? For those causing problems, briefly explain why. int* f1(void) { int y = 10; return (&y); } int* f2(void) { int* ptr; *ptr = 10; return ptr; } int* f3(void) { int *ptr; ptr = (int *) malloc (sizeof(int)); *ptr = 10; return ptr; } f1: [explanation goes here] f2: [explanation goes here] f3: [explanation goes here]
FOR C PROGRAMMING LANGUAGE ; please provide detailed explanation with detailed diagram Draw the main memory...
FOR C PROGRAMMING LANGUAGE ; please provide detailed explanation with detailed diagram Draw the main memory diagram as captured at the end of the C program (i.e. return 0; statement). Your diagram must clearly shows where str, p1, p2, and p3 are pointing to, when the program terminates. int main(void) { char str[] = "cs111 NYU"; char* p1 = str; p1 ++; char** p2 = &p1; char* p3 = &str[4]; printf("1. str = %s\n", p1); if(p3 - p1 == 4)...
Compile and run the following code and presuming your executable is in a.out, run this command...
Compile and run the following code and presuming your executable is in a.out, run this command from the shell prompt: ./a.out ; echo "Parent Terminated Normally with a return value of $?" Explain, in your own words, why you see the screen output you do and how that output relates to both the content of the program AND the nature of the shell command used to invoke it. Hint: This has everything to do with how processes “communicate” their exit...
How can i make this lunix code print 3 numbers in reverse it must be in...
How can i make this lunix code print 3 numbers in reverse it must be in printStars format and no loops Here is the code i have but can figure out how to reverse the numbers #include<stdio.h> void printStars(int n) { if (n>0){ printf(""); printStars(n-1); } } int main() { int n; int b; int c; printf("Enter 3 numbers to reverse "); scanf("%d",&n,&b,&c); printf("your reversed numbers are %d",n); printStars(n); return 0;
Below is C code and Python code for an algorithm. C code: void foo( int n,...
Below is C code and Python code for an algorithm. C code: void foo( int n, int A, int B, int C ) { if( n==1 ) { printf("%d to %d\n",A,B); return; } foo( n-1, A, C, B ); printf("%d to %d\n",A,B); foo( n-1, B, C, A ); Python code: def foo(n , A, B, C): if n==1: print A, "to", B return foo(n-1, A, C, B) print A, "to", B foo(n-1, B, C, A) Let Hn be the number...
In C language: Partially finished program is given below. The second and third parameters of the...
In C language: Partially finished program is given below. The second and third parameters of the count() function need to be pointer parameters. However, the programmer forgot to write the necessary ampersands and asterisks in the prototype, call, function header, and function code. Add these characters where needed so that changes made to the parameters adults and teens actually change the underlying variables in the main program. #include #define MAX 10 void count( int ages[], int adults, int teens );...
Run the below code and shift binary left and right and understand the output. #include <stdio.h>...
Run the below code and shift binary left and right and understand the output. #include <stdio.h> int main() {     int num=212, i;     for (i=0; i<=2; i++)         printf("Right shift by %d: %d\n", i, num>>i);      printf("\n");      for (i=0; i<=2; i++)         printf("Left shift by %d: %d\n", i, num<<i);             return 0; } Output:
C# Programming Write, compile, and test a program named Lyrics that displays at least four lines...
C# Programming Write, compile, and test a program named Lyrics that displays at least four lines of your favorite song. Code Patterns to follow are the following (All these have to check out: -Checks for correct use of WriteLine (4x) Description Searched your code for a specific pattern: (\s*WriteLine\(".*"\);\s*){4,} Start code with this outline: using static System.Console; class Lyrics {    static void Main()    {     // Write your main here    } }
Consider the following code that is contained in the main function of a C program. What...
Consider the following code that is contained in the main function of a C program. What is wrong with the code? unsigned int myUnsignedInt = 100; printf("%c\n", myUnsignedInt);
FOR C PROGRAMMING LANGUAGE Consider the following C programming language declaration. Find the values of the...
FOR C PROGRAMMING LANGUAGE Consider the following C programming language declaration. Find the values of the following. If undefined write undefined. int A[2][3] = { {1, 2, 3}, {4, 5, 6} }; A[1][0]: [Value goes here] *A[0]: [Value goes here] *(*A + 1): [Value goes here] **(A + 1): [Value goes here] **(A + 2): [Value goes here]
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT