What is string in C Tamil - linto.in
String in c tamil, group of characters or array of characters. அதாவது பல characters ஒன்று சேர்ந்த தொகுப்பே string எனப்படும்.
What is String?
String என்பது group of characters or array of characters. அதாவது பல characters ஒன்று சேர்ந்த தொகுப்பே string எனப்படும். Examole "welcome", "Shoping mall", "Jewells", etc,.
C Program-ல் string எப்போதும் NULL என்ற character-ஐ கொண்டு முடியும். NULL என்ற character, '\0' என்று வரையறுக்கபட்டுள்ளது.
1. String என்பது double quotes " "-க்குள் கொடுக்கபடுகின்றது. example "Never Make a Promise When You are Happy". String-ல் ஒன்று அல்லது அதற்க்கு மேற்பட்ட characters இருக்கலாம்.
2. Character என்பது single quotes ' '-க்குள் கொடுக்கபடுகின்றது. example 'A','t','6',' ', etc,. Character-ல் ஒரே ஒரு character மட்டுமே இருக்க வேண்டும்.
String datatype
C program-ல் float, int போன்று String-க்கு என்று தனி datatype கிடையாது. இதற்க்கு char datatype பயன்படுத்தபடுகிறது.
Different Ways of String Initialization
char []="C program";
char [30] = "C Program";
char []= {'C',' ','P','r','o','g','r','a','m'};
char [30] = {'C',' ','P','r','o','g','r','a','m'};
Simple Example for Print string
#include<stdio.h>
#include<conio.h>
int main(){
// declare and initialize string
char name[]= "Narayanamoorthi";
// print string
printf("%s",name);
return 0;
}
Output:
Narayanamoorthi
Why we have not used the '&' sign with variable in scanf statement?
ஒவ்வொரு variable-ன் value-வையும் input-ஆகா scanf-ல் கொடுக்கும்போதும் '&' பயன்படுத்துவது மிகவும் அவசியம். ஏனெனில் இது value-வை memory-ல் store செய்வதற்கான address-ஐ வழங்குகிறது. ஆனால் இங்கு string என்பது ஒரு character array ஆகையால் braces '[]'-ஐ நீக்கிவிட்டு variable-ஐ மட்டும் பயன்படுத்தினாலே போதும் அது string-ன் base address-ஐ கொடுத்து விடுகின்றது. ஆகையால் தான் '&' பயன்படுத்த வேண்டிய அவசியம் இல்லை.
Example
#include<stdio.h>
#include<conio.h>
int main()
{
// declaring string
char str[50];
printf("Enter a string: ");
// reading string
scanf("%s",str);
// print string
printf("%s",str);
return 0;
}
Output:
Enter a string: Welcome to new Way of learningWelcome to new Way of learning
String Functions
String-ஐ எளிமையாக கையாளுவதர்க்கு சில inbuild function-கள் உள்ளன. அவை பின்வருமாறு
- strcpy() - string copy
- strcat() - string concatenation
- strlen() - string length
- strupr() - string uppercase
- strlwr() - string lowercase
- strcmp() - string comparison
- strcmpi() - string comparison ignore case
- strrev() - string reverse