answersLogoWhite

0

What is return type of string in c?

Updated: 5/29/2023
User Avatar

Wiki User

11y ago

Best Answer

In C Programming, a string doesn't have a specific return type as it's essentially an array of characters. So, if a function is returning a string, it should be declared to return a pointer to a char (char*), since a string in C is represented as an array of characters terminated by a null character ('\0').

User Avatar

Erick

Lvl 4
11mo ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

There is No Such Type Called String in C. In C String is a character array..

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is return type of string in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Why to use String in c?

C doesn't have String data-type, so don't use it.


How do you get value of a string in reverse order in c?

Assume C#, not C: Traditional way: public string Reverse(string s) { if (string.IsNullOrEmpty(s)) return s; // "" or null char[] characters = s.ToCharArray(); Array.Reverse(characters); return new string(characters); } or as an extension method: public static string Reverse(this string s) { if (s == "") return ""; char[] characters = s.ToCharArray(); Array.Reverse(characters); return new string(characters); } The differences of the 2 methods above is on the caller (how to use Reverse()), and they may co-exist: For example: string test = "abc"; string result1 = Reverse(test); // traditional way string result2 = test.Reverse(); // call the extension


What is the difference between a C plus plus string and a C-style string?

A std::string is an object that encapsulates an array of type char whereas a C-style string is a primitive array with no members. A std::string is guaranteed to be null-terminated but a C-style string is not.


What is the default return type in C and C plus plus?

No. There is no default return type for functions, it must be explicitly specified in both the function declaration and in the definition. To specify no return value, return void. To return a variant type, return void* (pointer to void). Otherwise return the exact type.


C plus plus program to count digit in a string?

Use the following function to count the number of digits in a string. size_t count_digits (const std::string& str) { size_t count = 0; for (std::string::const_iterator it=str.begin(); it!=str.end(); ++it) { const char& c = *it; if (c>='0' && c<='9'); ++count; } return count; }

Related questions

Why to use String in c?

C doesn't have String data-type, so don't use it.


How do you get value of a string in reverse order in c?

Assume C#, not C: Traditional way: public string Reverse(string s) { if (string.IsNullOrEmpty(s)) return s; // "" or null char[] characters = s.ToCharArray(); Array.Reverse(characters); return new string(characters); } or as an extension method: public static string Reverse(this string s) { if (s == "") return ""; char[] characters = s.ToCharArray(); Array.Reverse(characters); return new string(characters); } The differences of the 2 methods above is on the caller (how to use Reverse()), and they may co-exist: For example: string test = "abc"; string result1 = Reverse(test); // traditional way string result2 = test.Reverse(); // call the extension


What is a c-string?

It Is the newest type of thong!


What is the difference between a C plus plus string and a C-style string?

A std::string is an object that encapsulates an array of type char whereas a C-style string is a primitive array with no members. A std::string is guaranteed to be null-terminated but a C-style string is not.


How do you get size of string with null valid character in visual c on socket network?

strlen will return 0, meaning empty string


What is the default return type in C and C plus plus?

No. There is no default return type for functions, it must be explicitly specified in both the function declaration and in the definition. To specify no return value, return void. To return a variant type, return void* (pointer to void). Otherwise return the exact type.


C plus plus program to count digit in a string?

Use the following function to count the number of digits in a string. size_t count_digits (const std::string& str) { size_t count = 0; for (std::string::const_iterator it=str.begin(); it!=str.end(); ++it) { const char& c = *it; if (c>='0' && c<='9'); ++count; } return count; }


How do you return a word in a string so that every letter is a symbol eg egg must be 3 symbols?

Not really sure what you mean by symbol. I will assume that you are talking about a character Here is a method that will seperate each char of a String in an array of char public char[] seperateChar(String s) { char [] c = new char[s.length]; for(int i = 0; i < s.length(); i++) { c[i] = s.charAt(i); } return c }


What does 'strtok' mean in computing?

A strtok is used as a search string in computing where it can find a variable that is typed after " " (add a space), and then return it as a string. It is part of the C++ programming technique.


Why the return type of all the function by default is int in c?

Because int is the most common data-type in C. Don't rely on this though, always specify the return type explicitly.


1 Define a class in C plus plus to store following information of books Title Author Publisher Price?

class Book { public: Book(std::string title, std::string author, std::string publisher, double price) : m_title(title), m_author(author), m_publisher(publisher), m_price(price) {} std::string get_title()const{return(m_title);} std::string get_author()const{return(m_author);} std::string get_publisher()const{return(m_publisher);} int get_price()const{return(m_price);} private: std::string m_title; std::string m_author; std::string m_publisher; double m_price; }


What are the valid type of data that the main can return in c language?

Type 'int'