0

int arr[100],temp1[n1],temp2[n2]; temp1 = arr[l];
temp2 = arr[j];

i am supposed to assign some part of an array of length 100 to two arrays using pointers without using any loops

ex:- l=10,j=43,n1=12,n2=13 now 12 elements from array have to be given to temp1 starting from 10th element and 13 elements have to be given to temp2 starting from 43

But using the above gives an error and assume that l,j,n1,n2 are given correctly before the declaration of the arrays . So suggest me a code to do this without loops and using pointers .

0

1 Answer 1

1

You cannot assign arrays in C, let alone assigning ranges from them. Instead, you copy memory of these arrays to new locations:

memcpy

This is done using memcpy function. Use &array[firstIndex] or array+firstIndex to compute the initial address of the block to be copied and the initial address in the destination array. Use n*sizeof(array[0]) to determine the number of bytes to be copied.

Sign up to request clarification or add additional context in comments.

1 Comment

@M.M You are right, thanks! The parentheses were unbalanced there, too.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.