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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:52:37+00:00 2026-05-28T14:52:37+00:00

Possible Duplicate: Is array name a pointer in C? Array Type – Rules for

  • 0

Possible Duplicate:
Is array name a pointer in C?
Array Type – Rules for assignment/use as function parameter

This is the code that i wrote for an exercise in K&R C. The task is pretty simple, to replace ‘\t’ with \ and t and not the tab character

the following is the code

char* escape(char s[], char t[]){
 int i = 0, j = 0;
 for(i = 0; t[i] != '\0'; i++){
   switch(t[i]){
     case '\t':{
        s[j++] = '\\';
        s[j++] = 't';
        break;
     }
     default:{
        s[j++] = t[i];
        break;
     }
   }
  }
 s[j] = t[i];
 return s;

 }


 int main(){        
    char t[10] = "what \t is";
    char s[50];
    s = escape(s,t);
    printf("%s",s);
    return 0;
 }

It returns an error saying inappropriate type assignment betweenn char[50] and char* but isn’t the name of the array supposed to be the pointer to the first element?

  • 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-28T14:52:38+00:00Added an answer on May 28, 2026 at 2:52 pm

    In C arrays aren’t writable lvalues. You can’t assign to them. In your code you don’t actually need to return anything from the function since it changes s in place. But if you really want to:

    char *s = malloc(...);
    s = escape(s, t);
    

    This means you will later have to free it etc. In short, don’t return anything from the function and it’s going to be ok.

    but isn’t the name of the array supposed to be the pointer to the
    first element

    That’s an over-simplification. Thing is arrays typically decay into pointers to the first element in certain contexts.

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

Sidebar

Related Questions

Possible Duplicate: Is array name a pointer in C? char arr[1024]; arr++ //move arr
Possible Duplicate: Is array name a pointer in C? So, I usually declare arrays
Possible Duplicate: java - Array brackets after variable name When writing a Java function
Possible Duplicate: php multi-dimensional array remove duplicate I have an array like this: $a
Possible Duplicate: MySQL query using an array How to use an array of values
Possible Duplicate: passing an empty array as default value of optional parameter in c#
Possible Duplicate: Javascript - array.contains(obj) What's wrong with this: var zipCodes =(['90001','90002','90003']); Test if
Possible Duplicate: Byte array in objective-c Am converting some Java code to Objective-C and
Possible Duplicate: VB.Net Initialising an array on the fly This maybe a stupid question,
Possible Duplicate: tcl array question - key with quotes I have the following code:

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.