Datatype Char,strcpy in C Programming - learnit

Home Top Ad

Post Top Ad

Saturday, April 3, 2021

Datatype Char,strcpy in C Programming

Datatype Char,strcpy in C Programming

Datatype Char,strcpy in C Programming

C-Data Types

Data types specify how we enter data into our programs and what type of data we enter. C language has some predefined set of data types to handle various kinds of data that we can use in our program. These datatypes have different storage capacities.


C language supports 2 different type of data types:

1.Primary data types:

These are fundamental data types in C namely integer(int), floating point(Float), character(Char) and Void.


2.Derived data types:

Derived data types are nothing but primary datatypes but a little twisted or grouped together like array, stucture, union and pointers. These are discussed in details later.


Data type determines the type of data a variable will hold. If a variable X is declared as int it means x can hold only integer values. Every variable, which is used in the program, must be declared as what data-type it is.


Character type

Character types are used to store characters value.

Size and range of Integer type on 16-bit machine

Type Size(Bytes) Range
Char or Signed Char 1 -128 to 127
UnSigned Char 1 0 to 255

The strcpy() Function in C

The strcpy() function is used to copy strings. It copies string pointed to by source into the destination. This function accepts two arguments of type pointer to char or array of characters and returns a pointer to the first string i.e destination. Notice that source is preceded by the const modifier because strcpy() function is not allowed to change the source string.


Example

#include<stdio.h> #include<conio.h> #include<string.h> int main() { char word[40]; strcpy(word,"Hello Knowledge Edcuation Cambodia"); printf("%s\n",word); getch(); }

Please Watching My Video is Below

No comments:

Post a Comment

Post Top Ad