Learning C
What is the difference between:
Int t[80]; & char t[80];
and when do I need to use int t[80];
Thanks........
Learning C
What is the difference between:
Int t[80]; & char t[80];
and when do I need to use int t[80];
Thanks........
int's are for holding numbers, and char's are for holding characters. It does get a little more complicated, but in essence, that's it.
The brackets [] represent an array (in your case, size 80).
I presume you're following a course or reading a tutorial? Either way, this type of thing is covered pretty early on... Try a web search for c data types if you're having problems.... or post a specific question here.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Thanks Hammer..........
But what confuses me is how come you can store integers mixed with characters in a char array???
The reason you can store both types in a char array is because every char is actually an int, and the int specifies exactly what type of char it is. If you've ever heard of ASCII codes, then you know what I mean. Each character symbol has a corresponding int that represents it.
That make perfect sense....so why do we need to use int array???
char is not exactly a type of int , they are both integral types , a char typically holds less values ,Originally posted by Max
That make perfect sense....so why do we need to use int array???
in my complier , the range of char is from 0 -255 while that of int is from -2147483647-1 to 2147483647 , you can have a look at the file limits.h to get an idea in your implementation
The one who says it cannot be done should never interrupt the one who is doing it.
char is not exactly a type of int , they are both integral types , a char typically holds less values ,Originally posted by Max
That make perfect sense....so why do we need to use int array???
in my complier , the range of char is from 0 -255 while that of int is from -2147483647-1 to 2147483647 , you can have a look at the file limits.h to get an idea in your implementation
The one who says it cannot be done should never interrupt the one who is doing it.
Here is what it boils down to. A char is an 8 bit number, on windows an int is 32 bit. A long int is 32 bits and a short is 16 bits. Here is one way of looking at it (using unsigned versions of each), if you want to know the limitations of that storage type just do (2^(number of bits/3))-1. Like an unsigned char can hold up to 255, an unsigned short can hold up to 65536 and on unsigned long can hold up to 4294967295. On a side note, floats are 32bit and doubles are 64.
how to count upper and lower case?
What has this got to do with this thread??!!Originally posted by Unregistered
how to count upper and lower case?
Anyways,
>#include <ctype.h>
Then use isupper() and islower().
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Screwed up browser !!!Originally posted by ygfperson
deja vu?
An int is for storing a number, which you can subsequently use in calculations if you want to. A char is for holding characters or alphanumerics. You cannot do calulations on numbers stored as a char without doing a type conversion (also referred to as casting or type casting). Why would you want to do this? You may want to store someones phone number for example. This consists of all numbers, but here in the UK all phone numbers commence with zero. If you stored this as an integer you would lose the leading zero, so you must store it as a string of characters. And the way that C implements a string is as an array of characters eg char[11].
You are wrong , you can add,subtract two characters ,in fact you can do all things you can do with integers , characters are like integers with a different range of values .Originally posted by clancyPC
An int is for storing a number, which you can subsequently use in calculations if you want to. A char is for holding characters or alphanumerics. You cannot do calulations on numbers stored as a char without doing a type conversion (also referred to as casting or type casting). Why would you want to do this? You may want to store someones phone number for example. This consists of all numbers, but here in the UK all phone numbers commence with zero. If you stored this as an integer you would lose the leading zero, so you must store it as a string of characters. And the way that C implements a string is as an array of characters eg char[11].
The one who says it cannot be done should never interrupt the one who is doing it.