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

  • Home
  • SEARCH
  • 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 9214689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:01:32+00:00 2026-06-18T02:01:32+00:00

In C, is there any built-in array slicing mechanism? Like in Matlab for example,

  • 0

In C, is there any built-in array slicing mechanism?

Like in Matlab for example,
A(1:4)

would produce =

 1     1     1     1

How can I achieve this in C?

I tried looking, but the closest I could find is this: http://cboard.cprogramming.com/c-programming/95772-how-do-array-subsets.html

subsetArray = &bigArray[someIndex]

But this does not exactly return the sliced array, instead pointer to the first element of the sliced array…

Many 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-06-18T02:01:33+00:00Added an answer on June 18, 2026 at 2:01 am

    Thanks everyone for pointing out that there is no such built-in mechanism in C.

    I tried using what @Afonso Tsukamoto suggested but I realized I needed a solution for multi-dimensional array. So I ended up writing my own function. I will put it in here in case anyone else is looking for similar answer:

    void GetSlicedMultiArray4Col(int A[][4], int mrow, int mcol, int B[1][4], int sliced_mrow)
    {
        int row, col;
        sliced_mrow = sliced_mrow - 1; //cause in C, index starts from 0
        for(row=0; row < mrow; row++)
        {
            for (col=0; col < mcol; col++)
            {
                if (row==sliced_mrow) B[0][col]=A[row][col];
            }
        }
    }
    

    So A is my input (original array) and B is my output (the sliced array).
    I call the function like this:

    GetSlicedMultiArray4Col(A, A_rows, A_cols, B, target_row);
    

    For example:

    int A[][4] = {{1,2,3,4},{1,1,1,1},{3,3,3,3}};
    int A_rows = 3; 
    int A_cols = 4; 
    int B[1][4]; //my subset
    int target_row = 1;
    
    GetSlicedMultiArray4Col(A, A_rows, A_cols, B, target_row);
    

    This will produce a result (multidimensional array B[1][4]) that in Matlab is equal to the result of A(target_row,1:4).

    I am new to C so please correct me if I’m wrong or if this code can be made better… thanks again 🙂

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

Sidebar

Related Questions

Is there any built in MATLAB command that stretches out a multidimensional array into
Is there any built-in function in Python3/Numpy which filters an array and returns indices
1) Is there any built-in which can tell me if a variable's contents contain
If there is any built-in function for getting random letters like RANDOM(low,high) we used
Is there any Array or Enumerable built-in that allows me to search for an
Is there any built-in function that can return the length of an object? For
Let's say I have this array: var a = [1,2,99,3,4,99,5]; I would like to
PHP treats all arrays as associative, so there aren't any built in functions. Can
Is there any built-in support for that? And if not, is there any consensus
Is there any built in functionality that enables downloading files from FTP in .NET?

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.