Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6975675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:23:56+00:00 2026-05-27T17:23:56+00:00

I have: #include <stdio.h> int sum ( int x, int y ); main ()

  • 0

I have:

 #include <stdio.h>

 int sum ( int x, int y );

 main ()
 {
 int theSum = sum (10, 11);
 printf ( "Sum of %i and %i is: %i\n", x, y, theSum );
 }

 int sum ( int x, int y )
 {
 return x + y;
 }

However, when I compile and run it says x and y are undeclared? Any help greatly appreciated. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:23:57+00:00Added an answer on May 27, 2026 at 5:23 pm

    In line three all you have done is declare a function sum which takes two parameters, both integers, called x and y. You haven’t declared any variables. Those parameters can only be referred to inside the function itself. Below is a simplification which will help you at this stage, but you should try to read a basic programming book. “The C Programming Language” by Kernighan and Ritchie is a fine place to start.

    Variables are chunks of memory that you refer to by name. They can take on any value (of their type) during the life of your program – hence the name ‘variable’. They must be declared before you use them; you do this by telling the compiler their type and their name. int a means ‘reserve me a block of memory big enough to hold any integer, and let me refer to it later with the name a‘. You can assign values to it: a = 10 and you can make use of it: a + 20.

    You need to understand the difference between parameters and variables to get what’s going on here. A function’s parameters are basically variables which exist only during the life of that function. Here’s your sum again:

    int sum(int x, int y) {
        return x + y;
    }
    

    Notice how the top line looks just like a variable declaration int x. That’s because it is. x and y are variables you can use in the function.

    You call sum by passing in values. The compiler, in effect, replaces x and y in your function with the values you pass in. In your case, you’re passing literals: 10 and 11. When the program reaches the call to sum, the parameters x and y take on the values 10 and 11, so the return becomes return 10 + 11; which is of course 21.

    Just remember that the parameters x and y only exist in that function. You may only refer to them within your function. Why? Because each pair of curly braces { and } define a scope, and anything declared within that scope can only be used within that scope. That includes variables and parameters.

    So, here is a more complete example. I have changed the letters so you can see the different ways you use variables and parameters:

    #include <stdio.h>
    
    int sum ( int x, int y );
    
    main ()
    {
       /* We declare our variables */
       int a;
       int b;
    
       /* We assign values to them */
       a = 10;
       b = 11;
    
       /* We pass them as parameters to your sum function */
       int theSum = sum (a, b);
       /* And we use them as parameters again, in a call to the printf function */
       printf ( "Sum of %i and %i is: %i\n", a, b, theSum );
    }
    
    int sum ( int x, int y )
    {
       return x + y;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following code: #include <stdio.h> int main(void) { float a[4] __attribute__((aligned(0x1000))) =
I have a following parallel snippet: #include <omp.h> #include stdio.h int main() { omp_set_num_threads(4);
Let's say we have 2 source files: main.c: #include <stdio.h> #define i 2 int
Let us say i have File1.c: #include<stdio.h> #includeFile2.c void test(void) { sum(1,2); } int
Suppose that I have those three files: a.h //a.h header #include <stdio.h> int int_variable;
So I have this code: #include <stdio.h> int arraySum (int *a, int n); int
Currently I have this code, and it works. #include <stdio.h> int isFactor(long number1, long
The code: #include stdafx.h #include stdio.h #include math.h #include stdlib.h #include time.h int main()
I am on ubuntu linux 10.04 I have the following #simplec.c #include stdio.h int
I have a program here: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/ipc.h> #include

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.