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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:17:13+00:00 2026-06-01T02:17:13+00:00

I have an NxN 2D array implemented as a 1D array using A[N*i+j]. I

  • 0

I have an NxN 2D array implemented as a 1D array using A[N*i+j]. I want to make references to the columns of the array and be able to pass them to functions as regular column vectors. You can see an example below for N=3. The function returns just the square of the vector passed to it:

#include <stdio.h>

int func(int* vec[3]){
    int result=0;
    for(int i=0;i<3;i++){
        result+=(*vec[i])*(*vec[i]);
        printf("vec[%d]=%d\n",i,*vec[i]);
    }
    return result;
}

void main(){
    int A[]={0,1,2,3,4,5,6,7,8};

    int *a[3][3];

    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            a[j][i]=&A[3*i+j];
        }
    }
    for(int i=0;i<3;i++){
        printf("vector %d\n",i);
        for(int j=0;j<3;j++){
            printf("%d\n",*a[i][j]);
        }
    }

    printf("%d\n",func(a[0]));
}

This works but the problem is the function works only for arguments of type int* vec[3]. What I would really like is to have the function taking an argument of type int vec[3] but I’m confused on how I should then pass the vector of pointers as a vector of the values the vector elements point to.

  • 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-06-01T02:17:15+00:00Added an answer on June 1, 2026 at 2:17 am

    It is not possible to do what you want, atleast not in C.

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

Sidebar

Related Questions

Suppose you have an NxN grid, and you want to visit every cell exactly
I currently have a nxn array of ints. I plan to initialize all the
I have a NxN matrix which I want to split into non-overlap KxK block.
I have a NxM matrix and I want to compute the NxN matrix of
I have an array of size n^2 representing a square grid of size nxn.
I'm implementing NxN puzzle in 2D array in Java. I have the following classes:
Suppose you have an NxN matrix and you have to check whether it's a
Have just started using Google Chrome , and noticed in parts of our site,
Have just started using Visual Studio Professional's built-in unit testing features, which as I
The Algorithm traverses a 2D NxN array, making every element the average of its

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.