0

So my question is that if I have the following code

main(){
char arr[1][3];
foo(arr);
}

void foo(char arr1[1][3]){

arr1[0] = "AB\0";
}

Does this mean that the value in arr from main would also be modified into "AB\0"?

2
  • You should first search if similar qus asked or not.... Commented Dec 7, 2013 at 5:15
  • Got it, thank you. Yea, I need to modify my keywords during searching... appreciate your time. Commented Dec 7, 2013 at 5:17

2 Answers 2

3

Try checking this stack overflow question and answer, it is an age-old question

Passing an array by reference in C?

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

Comments

0

Why not test it out yourself?

#include <stdio.h>

void foo(char arr[]);

int main(int argc, char **argv)
{
    char arr[5] = "test";
    printf("%s\n", arr);

    foo(arr);
    printf("%s\n", arr);

    return 0;
}

void foo(char arr[])
{
    arr[0] = 'p';
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.