notesonly.in

One notebook for every subject — open it anywhere.

Log in

Arrays and strings

Programming Fundamentals · Engineering

Study notes

Reverse a string in C: char s[]="hello"; int n=strlen(s); for(int i=0;i<n/2;i++){ char t=s[i]; s[i]=s[n-1-i]; s[n-1-i]=t; } Result: "olleh". The null terminator at s[5] stays untouched.

← Back to topics for Engineering