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//BY SAMEERAZ
2#include<stdio.h>
3#include<conio.h>
4void main(){
5char string[50];
6clrscr();
7printf("ENTER STRING:");
8gets(s);//gets is basically used as scanf();
9printf("TYPED STRING:%s",string);
10getch();
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
1#include <stdio.h>
2int main(){
3 char name[10];
4 printf("What is your name: \n");
5 scanf("%s", name);
6 printf("Hello, %s!\n", name);
7}