DebuggingAdd two numbers using the pointer to function fill the remaining code to perform additionoutput:60 Font SizeLanguage Editor Theme #include <stdio.h>int sum(int x, int y){ return x+y;}int main( ){ int (*fp)(int, int); fp = sum;
Question
DebuggingAdd two numbers using the pointer to function fill the remaining code to perform additionoutput:60 Font SizeLanguage Editor Theme #include <stdio.h>int sum(int x, int y){ return x+y;}int main( ){ int (*fp)(int, int); fp = sum;
Solution
Sure, here is the completed code in C:
#include <stdio.h>
int sum(int x, int y){
return x+y;
}
int main( ){
int (*fp)(int, int);
fp = sum;
int a = 30;
int b = 30;
printf("%d", (*fp)(a, b));
return 0;
}
In this code, we first define a function sum that takes two integers and returns their sum. Then in the main function, we declare a function pointer fp that points to the sum function. We then declare two integers a and b, assign them the values 30 each, and then use the function pointer fp to call the sum function with a and b as arguments. The result is printed to the console.
Similar Questions
DebuggingAdd two numbers using the pointer to function fill the remaining code to perform additionoutput:60 Font SizeLanguage Editor Theme #include <stdio.h>int sum(int x, int y){ return x+y;}int main( ){ int (*fp)(int, int); fp = sum;
What does the term 'debug' mean?*1 pointIdentify errors and fix them.Making a calculationA set of instructionsLooking at code
Add two numbersYou have been provided with some code. The code should take in two numbers from the user, add them together, and then display the result to the user. However, the code has bugs!Debug this code!Here are some examples of how the program should work:Example 1Enter a number: 32Enter another number: 64The sum of your two numbers is: 96.00Example 2Enter a number: 1234.5678Enter another number: 9999.99The sum of your two numbers is: 11234.56Example 3Enter a number: 23Enter another number: -532.824The sum of your two numbers is: -509.82
Debug the given code to print the desired output.Sample InputCC++Sample OutputC++ Font SizeLanguage Editor Theme #include<iostream>#include<string>using namespace std;1234567891011121314151617181920212223class A{ public: string word1; string word2; A() { cin>>word1; cin>>word2; } void display() { cout <<word1<<endl; } }; class B:public A { public: void display() { cout <<word2<<endl; } }; int main() { A* a; B b; a = &b; a->display(); }
Write a program to add two numbers using pointers
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.