How to return string literal from a function in C++

1 Answer

0 votes
#include <iostream>

const char *get_string_literals() {
    return "string literal";
}

int main(void)
{
    const char *str = get_string_literals();
     
    std::cout << str;
}
 
 
 
 
/*
run:
 
string literal
 
*/

 



answered Dec 8, 2023 by avibootz

Related questions

1 answer 220 views
220 views asked Nov 23, 2020 by avibootz
1 answer 160 views
160 views asked Mar 9, 2025 by avibootz
1 answer 196 views
196 views asked May 10, 2021 by avibootz
1 answer 192 views
2 answers 276 views
276 views asked May 15, 2021 by avibootz
3 answers 391 views
391 views asked May 14, 2021 by avibootz
...