How to get the nth character of a string in C

How to get the nth character of a string in C

In this post we will give you information about How to get the nth character of a string in C. Hear we will give you detail about How to get the nth character of a string in CAnd how to use it also give you demo for it if it is necessary.

we will learn how to get the nth character of a string in C.

In C language, strings are the array of characters, where the index of the first character is 0, the second character is 1 etc.

Getting the nth character

To access the nth character of a string in C, we can use the square brackets [] notation by passing the character index.

Here is an example, that gets the first characterG from the following string:

#include <stdio.h>int main() {  char name[5] = "Gowtham";  char firstCharacter = name[0];  printf("First Character is : %c", firstCharacter);}

Output:

"G"

We can access the other characters of a string like this:

char secondCharacter = name[1];char thirdCharacter = name[2]

Hope this code and post will helped you for implement How to get the nth character of a string in C. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US