06-21-2011
Each integer datatype (includes char) has a range of values that it can work with.
Variables. Data Types. - C++ Documentation
Read the 'fundamental datatypes' section. It explains the range of each type.
Only you know the kind of data your program will use:
character strings == array of char
letter of the alphabet == char
integer numbers == int (long is often the same as int on 32 bit machines)
signed number dpend on whether you will be doing arithmetic operations and
what those are. Basically you should consider using signed variables simple yo avoid confusion: signed variables use a different printf() format specifier from unsigned variables. Keeping every integer as signed (int, long) makes housekeeping easier.
Read /usr/include/limits.h to see what the ranges are on your machine.
This User Gave Thanks to jim mcnamara For This Post:
10 More Discussions You Might Find Interesting
1. Programming
How can I store and/or print() a number that is larger than 4 294 967 295 in C? is int64_t or u_int64_t what I need ? if, so how can I printf it to stdout? (2 Replies)
Discussion started by: nimnod
2 Replies
2. Programming
hi,
Please help me with the following code to get the difference in values.
struct a{
int b1;
int c1;
char d1;
}
main()
{
unsigned int b=10;
unsigned int c;
c = b - (unsigned int )sizeof(a);
printf("%d",c);
}
Here c returns some junk value. How can i get the... (2 Replies)
Discussion started by: naan
2 Replies
3. UNIX for Dummies Questions & Answers
hello everybody!
I want to create a file with permissions for read, write, and execute to everybody using C, so I write this code:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(){
int fileDescriptor;
fileDescriptor =... (2 Replies)
Discussion started by: csnmgeek
2 Replies
4. Red Hat
Hello everey one,
here i am attempting to compile a c++ project .it's throughing the following errors.
my machine details are as follows:
Linux chmclozr0119 2.6.18-53.el5 #1 SMP Wed Oct 10 16:34:19 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux
errors:
=====
Generating... (0 Replies)
Discussion started by: mannam srinivas
0 Replies
5. Shell Programming and Scripting
Hi ,
I am using getopt for both short and long options as below
SHORTOPTS="a:c"
LONGOPTS="alpha:,charlie"
OPTS=$(getopt -o $SHORTOPTS --longoptions $LONGOPTS -n "$progname" -- "$@")
eval set -- "$OPTS"
while ; do
case $1 in
-a|--alpha)
echo "-a or --alpha... (1 Reply)
Discussion started by: padmisri
1 Replies
6. Shell Programming and Scripting
Hi All,
I have written the below to add the numbers in a column. Postive numbers are unsigned and negative numbers are signed in the file. After the below cmd I am getting -0.00 , instead of 0.00. Can someone guide me on what I am missing in the cmd.
grep '^L' $FileName| awk -F"|" ' {... (7 Replies)
Discussion started by: gsjdrr
7 Replies
7. Programming
Hi,
I wrote a simple code in C++ converting from UpperToLower case characters. However, my compiler gives me a warning:
"warning: conversion to 'char' from 'int' may alter its value".
Any tips?
I would like to stress, I don't want to load my string into char array.
int ToLower(string... (4 Replies)
Discussion started by: kajolo
4 Replies
8. Programming
/******************************************************************************/
/* Printing an unsigned character in bits */
#include <stdio.h>
void display_bits ( unsigned char );
int main()
{
unsigned char x; /*... (15 Replies)
Discussion started by: robin_simple
15 Replies
9. Programming
when a date type is considered signed and unsigned is that simple referring to - for signed and positive numbers for unsigned? Further if that is the case would mutiplying and dividing ect where 2 signed numbers, like (-2)*(-2) = 4 result in a unsigned. (3 Replies)
Discussion started by: Fingerz
3 Replies
10. OS X (Apple)
Hi guys...
Macbook Pro, 13", circa August 2012, OSX 10.7.5, default bash terminal.
I require the capability to convert +32767 to -32768 into signed hex words...
The example piece code below works perfectly except...
#/bin/bash
# sign.sh
# Unsign to sign...
while true
do
# I have used... (2 Replies)
Discussion started by: wisecracker
2 Replies
ltostr(3C) ltostr(3C)
NAME
ltostr(), ultostr(), ltoa(), ultoa() - convert long integers to strings
SYNOPSIS
Obsolescent Interfaces
DESCRIPTION
Convert a signed long integer to the corresponding string
representation in the specified base. The argument base must be between 2 and 36, inclusive.
Convert an unsigned long integer to the corresponding string
representation in the specified base. The argument base must be between 2 and 36, inclusive.
Convert a signed long integer to the corresponding base 10
string representation, returning a pointer to the result.
Convert an unsigned long integer to the corresponding base 10
string representation, returning a pointer to the result.
These functions are smaller and faster than using for simple conversions (see printf(3S)).
Obsolescent Interfaces
convert long integers to strings.
ERRORS
If the value of base is not between 2 and 36, and return NULL and set the external variable to ERANGE.
WARNINGS
The return values for and point to data whose content is overwritten by subsequent calls to these functions by the same thread.
and are obsolescent interface supported only for compatibility with existing DCE applications. New multi-threaded applications should use
and
AUTHOR
and were developed by HP.
SEE ALSO
strtol(3C), printf(3S), thread_safety(5).
ltostr(3C)