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 7005733
In Process

The Archive Base Latest Questions

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

I started a different thread for this, I tried solving it using the help

  • 0

I started a different thread for this, I tried solving it using the help they gave me but I am not able to run the program. Can anyone tell me what is wrong in the program and how is it supposed to be? Thanks.

The program is supposed to add an array to itself and replace the original with the sum, so when the initial array is printed, it prints the sum. This is what I have done so far.

Please note it is a must to use ADDER(a,a) as a function call. I am not allowed to change that. Both parameters are to be passed by reference.

#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

int size; //global variable

void ADDER(int *a, int *b) {
    int i;
    for (i = 0; i < size; i++) {
        b[i] += a[i];
    }     
}

int main() {
    int n, i;
    printf("Enter the number of elements: ");
    scanf("%d", &n);
    int *a = (int *)malloc(n*sizeof(int));
    int *b;
    for (i=0; i<n; i++) {
        printf("Enter element number %d: ", i);
        scanf("%d", &a[i]);
    }
    ADDER(a,a);
    for (i=0; i<n; i++) {
        printf("%d", a[i]);
    }
}

Errors:

1>—— Build started: Project: adderTest, Configuration: Debug Win32 ——

1> adder.c

1>e:\my documents\visual studio 2010\projects\addertest\addertest\adder.c(17): warning C4996: ‘scanf’: This function or variable may be unsafe. Consider using scanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

1> e:\program files\microsoft visual studio 10.0\vc\include\stdio.h(304) : see declaration of ‘scanf’

1>e:\my documents\visual studio 2010\projects\addertest\addertest\adder.c(18): error C2143: syntax error : missing ‘;’ before ‘type’

1>e:\my documents\visual studio 2010\projects\addertest\addertest\adder.c(19): error C2143: syntax error : missing ‘;’ before ‘type’

1>e:\my documents\visual studio 2010\projects\addertest\addertest\adder.c(22): error C2065: ‘a’ : undeclared identifier

1>e:\my documents\visual studio 2010\projects\addertest\addertest\adder.c(22): error C2109: subscript requires array or pointer type

1>e:\my documents\visual studio 2010\projects\addertest\addertest\adder.c(24): error C2065: ‘a’ : undeclared identifier
1>e:\my documents\visual studio 2010\projects\addertest\addertest\adder.c(24): warning C4047: ‘function’ : ‘int *’ differs in levels of indirection from ‘int’

1>e:\my documents\visual studio 2010\projects\addertest\addertest\adder.c(24): warning C4024: ‘ADDER’ : different types for formal and actual parameter 1

1>e:\my documents\visual studio 2010\projects\addertest\addertest\adder.c(24): error C2065: ‘a’ : undeclared identifier

1>e:\my documents\visual studio 2010\projects\addertest\addertest\adder.c(24): warning C4047: ‘function’ : ‘int *’ differs in levels of indirection from ‘int’

1>e:\my documents\visual studio 2010\projects\addertest\addertest\adder.c(24): warning C4024: ‘ADDER’ : different types for formal and actual parameter 2

1>e:\my documents\visual studio 2010\projects\addertest\addertest\adder.c(26): error C2065: ‘a’ : undeclared identifier

1>e:\my documents\visual studio 2010\projects\addertest\addertest\adder.c(26): error C2109: subscript requires array or pointer type

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

  • 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-27T21:23:19+00:00Added an answer on May 27, 2026 at 9:23 pm
    #include <stdlib.h>
    #include <stdio.h>
    
    /* global variable to store the size */
    int g_size;
    
    void ADDER(int *a, int *b) 
    {
        int i;
        for (i=0 ; i<g_size ; i++) {
            b[i] += a[i];
        }
    
        return;     
    }
    
    int main(void) 
    {
        int n, i;
    
        printf("Enter the number of elements: ");
        scanf("%d", &n);
    
        int *a = NULL;
        if ((a = (int *)malloc(n * sizeof(int))) == NULL) {
            printf("unable to allocate memory \n");
            return -1;
        }
    
        for (i=0; i<n; i++) {
            printf("Enter element number %d: ", i);
            scanf("%d", &a[i]);
        }
    
        g_size = n;
        ADDER(a, a);
    
        for (i=0; i<n; i++) {
            printf("%d \n", a[i]);
        }
    
        free(a);
        return 0;
    }
    

    I made the following modifications:

    • error checking for malloc()
    • once done, free()‘ed the memory
    • formatted output
    • removed conio.h as it is not needed
    • and, finally made it work! 🙂

    EDIT: Update the code as per the request of the OP author.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Started with this question: OpenID. How do you logout OK. So OpenID does not
I'm having trouble getting the GPS's onLocationChanged to run on a different thread. I
I've started my own thread on this question so as to have less overhead
Our commercial application used to run on different application server and letely we started
When I try hitting the Space Bar nothing happens. I tried this with different
I have a some computation program. Now, this program is a single-thread, I need
I wrote a program in C++ under Linux. For thread I am using pthread.
First of all, I realize this is a messy situation, but it's not of
Posted this on the structuremap group as well. We just started using structuremap last
Multiple NSURLConnections being started (in a single UIViewController) to gather different kinds of data.

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.