Question

char *s = "hello"; Can I access the character 'h' by doing s[0] or not ;...

char *s = "hello";

Can I access the character 'h' by doing s[0] or not ;

and moreover what is the diff b/w the above and

char s[]= " hello " ;

0 0
Add a comment Improve this question Transcribed image text
Answer #1
char *s = "hello";
Can I access the character 'h' by doing s[0] or not ;
Yes, you can access h using s[0]. same way you can access e using s[1], etc..

and moreover what is the diff b/w the above and
char s[]= " hello ";

char *s = "hello"; this creates a string with 5 characters 'h', 'e', 'l', 'l', 'o'
char s[]= " hello "; this creates a string with 7 characters ' ', 'h', 'e', 'l', 'l', 'o', ' '.
note a single space is also a character
char s[]= " hello "; has a space before and after hello.
Add a comment
Know the answer?
Add Answer to:
char *s = "hello"; Can I access the character 'h' by doing s[0] or not ;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • at what times we can use 1 dimensional array strings for I,e char s[10]; and when...

    at what times we can use 1 dimensional array strings for I,e char s[10]; and when can we use i.e char s[2][10] ; Can you please let me know the diff

  • Part I. Representation of a String The primitive type char is used to store a single...

    Part I. Representation of a String The primitive type char is used to store a single character, whether it is a letter, number or special character (for example: space, tab, or new line). More often, we want to store a string of characters in a single variable. We can do this by using a variable of the class type String. A String variable can be initialized to a String literal (which is similar to how a char variable can be...

  • Hello Can someone tell me what I am doing incorrectly for this problem? NOTE:X1,X2,...,Xn are independent....

    Hello Can someone tell me what I am doing incorrectly for this problem? NOTE:X1,X2,...,Xn are independent. The question is on the top of this page. If you can recognize the problem, solve it using the same method as above. Thanks.

  • hi this is c++ i hope you can see but the number 3 is char &r...

    hi this is c++ i hope you can see but the number 3 is char &r = c2; everything else looks readable thank you 4. (8 pts) Given the following code snippet: I char c1 'x', c2 'y', c3 z'; t char *pl &c1, *p2 &c3; 3chare c2; Tp2 w s p2 pl; p1 &c3; " << c2 << ", < c3 < endl; cout << *p1 <« ", " « *p2 « ", " «r « endl; cout <<...

  • Hello Everyone . I hope you are doing well . This is my question : THANK...

    Hello Everyone . I hope you are doing well . This is my question : THANK YOU. Question I: Write a C-program to receive a character from a PC to PIC16F877a Microcontroller with a baud rate 19200 and a frequency of 10MHz using serial communication. 1. Write and compile the Program Using MPLAB X. 2. Simulate the system using ISIS proteus and show the simulation results.

  • Create a UNIX makefile for the following C program: //convert.c char toUpper(char c){ if(c>='a' && c<='z')...

    Create a UNIX makefile for the following C program: //convert.c char toUpper(char c){ if(c>='a' && c<='z') return c-32; return c; } //converting sentance to upper void convertSentence(char *sentence){ int i=0; while(sentence[i]!='\0'){ //convert to upper for each character sentence[i] = toUpper(sentence[i]); i++; } } //converting all sentences into uppercase void convertAll(char **sentenceList, int numOfSentences){ int i=0; while(i<numOfSentences){ //calling convertsentence function to conver uppercase convertSentence(sentenceList[i]); i++; } } sentences.c #include<stdio.h> #include<stdlib.h> #include "convert.c" int main(){ //declaring character array char **mySentences; int noOfSentences;...

  • Needs to be done in C, The function shown can be called to reverse the char....

    Needs to be done in C, The function shown can be called to reverse the char. 7.5 Bit Encryption 7.5.1 Problem Given a single character, apply a simple bitwise encryption algorithm and return the cipher character. 7.5.2 Preconditions You must provide a series of functions which meet the requirements in the table below. You you may include other functions as long as the requested functions execute correctly. Do not include a main function in your source or header files. You...

  • why is this wrong for vectors vector<char> decrypt{ {'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',...

    why is this wrong for vectors vector<char> decrypt{ {'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A'}, {'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B'}, }; for(int...

  • hello how are you ? I hope you are doing well can you please help me...

    hello how are you ? I hope you are doing well can you please help me to understand what is western bolting by writing a summary that describe a situation where you would need this technique and the steps of the procedure or how it works. thank you so much

  • Given the declaration char letter[3][3] = { {'a', 'b', 'c'}, {'d', 'e','f'}, {'g', 'h', 'i'} };...

    Given the declaration char letter[3][3] = { {'a', 'b', 'c'}, {'d', 'e','f'}, {'g', 'h', 'i'} }; which character is stored in letter[3][2]?

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT