C Array Traversing In Hindi


पिछले topic में आपने C में array के बारे में पढ़ा और समझा कि कैसे array को define करते हैं single elements को access करते हैं। इस topic में आप सीखेंगे कि for loop और while loop की help से कैसे array को traverse कर सकते हैं।

C में Array को आप for loop और while loop दोनों से traverse कर सकते हो।

C array traversal with while loop

#include <stdio.h> int main() { // define string array. char* users[5] = {"Rahul", "Ravi", "Raju", "Ram", "Shyam"}; int index=0; while( index < 5) { printf("Index %d : %s\n", index, users[index]); // increase value by 1. index++; } return 0; }

Output :

Index 0 : Rahul
Index 1 : Ravi
Index 2 : Raju
Index 3 : Ram
Index 4 : Shyam

Note - Example में \n का use line break करने के लिए किया गया है।

C array traversal with for loop

अब same example को for loop की help से iterate करके देखेंगे।

#include <stdio.h> int main() { // define string array. char* users[5] = {"Rahul", "Ravi", "Raju", "Ram", "Shyam"}; for(int index=0; index < 5; index++) { printf("Index %d : %s\n", index, users[index]); } return 0; }

Output :

Index 0 : Rahul
Index 1 : Ravi
Index 2 : Raju
Index 3 : Ram
Index 4 : Shyam

Hey ! I'm Rahul founder of learnhindituts.com. Working in IT industry more than 5.5 years. I love to talk about programming as well as writing technical tutorials and blogs that can help to others .... keep learning :)

Get connected with me - LinkedIn Twitter Instagram Facebook