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 150 views
150 views asked Nov 23, 2020 by avibootz
1 answer 133 views
133 views asked May 10, 2021 by avibootz
1 answer 79 views
79 views asked Mar 9, 2025 by avibootz
1 answer 116 views
2 answers 189 views
189 views asked May 15, 2021 by avibootz
3 answers 233 views
233 views asked May 14, 2021 by avibootz
...