1char greeting[6] = {'H', 'e', 'l', 'l', 'o', '\0'};
2char greeting[] = "Hello";
1#include <stdio.h>
2
3int main(void) {
4 char name[] = "Harry Potter";
5
6 printf("%c", *name); // Output: H
7 printf("%c", *(name+1)); // Output: a
8 printf("%c", *(name+7)); // Output: o
9
10 char *namePtr;
11
12 namePtr = name;
13 printf("%c", *namePtr); // Output: H
14 printf("%c", *(namePtr+1)); // Output: a
15 printf("%c", *(namePtr+7)); // Output: o
16}
1#include <stdio.h>
2int main()
3{
4 char name[30];
5 printf("Enter name: ");
6 fgets(name, sizeof(name), stdin); // read string
7 printf("Name: ");
8 puts(name); // display string
9 return 0;
10}
11