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
1#include <stdio.h>
2void displayString(char str[]);
3
4int main()
5{
6 char str[50];
7 printf("Enter string: ");
8 fgets(str, sizeof(str), stdin);
9 displayString(str); // Passing string to a function.
10 return 0;
11}
12void displayString(char str[])
13{
14 printf("String Output: ");
15 puts(str);
16}
17