#include <stdio.h>
int main(void){
char x [] = "hello world.";
printf("%s \n", &x[0]);
return 0;
}
The above code prints out "hello world."
How would i print out just "h"? Shouldn’t the access x[0] ensure this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
You should do:
The format specifier to print a char is
c. So the format string to be used is%c.Also to access an array element at a valid index
iyou need to sayarray_name[i]. You should not be using the&. Using&will give you the address of the element.