CIS6 Chapter 3

¡Supera tus tareas y exámenes ahora con Quizwiz!

C Data keywords include 12

Original: int (basic class of integers used in C) *long (the bolds are used to provide variations of the basic type) short unsigned* char (the type used for letters of the alphabet and for other characters, also can be used to represent small integers ) float/double (are used to represent numbers with decimal points) C90 *signed void* C99 _Bool. (for Boolean values true and false) _Complex (represent complex and imaginary numbers) _Imaginary

When you initialize a variable

match the constant type to the variable type int apples = 3; int oranges = 3.0;

long long

may use more storage than long. At the minimum, it must use at least 64 bits. Like int, long long is a signed type.

short

may use less storage than int, thus saving space when only small numbers are needed. Like int, short is a signed type.

long

may use more storage than int, thus enabling you to express larger integer values. Like int, long is a signed type.

\n

newline; sets the active position to the beginning of the next line.

\0oo

octal value

%e

print in exponential notation

\?

question mark

char grade = 'B';

represents 'B' as the numerical value 66 stored in a 32-bit unit, but grade winds up with 66 stored in an 8-bit unit.

scanf() vs printf()

scanf() -gets keyboard input -this function provides keyboard input to the program -function reads data from the keyboard and delivers that data to the program printf() -displays program output -reads data from a program and delivers that data to your screen.

basic integer type

short long unsigned

\'

single quote (')

A variable is used to

store a value and retrieve a value

scanf("%f, &weight);

the %f instructs scanf() to read a floating-point number from the keyboard, and the &weight tells scanf() to assign the input value to the variable name weight. The scanf() function uses the & notation to indicate where it can find the weight variable.

&ch; what is the & for

the ampersand causes the character to be assigned to the variable ch.

buffer

the intermediate storage area printf( ) statements send output to.

data

the numbers and characters that bear the information you use

precision

the precision specifier indicates

Initializing a Variable

to initialize a variable means to assign it a starting, or initial value. just follow the variable name with the assignment operator (=) and the value you want the variable to have. int hogs=21; int cows = 32, goats = 14, int dogs, cats = 94;

%lx

to print a long integer in hexadecimal format

%lo

to print a long integer in octal format

the function call scanf ("%d, &weight) has ____________ arguments.

two : "%d" and &weight.

variables

types of data that may change or be assigned values as the program runs

Both the h and l prefixes can be used with ___ for ______________ types

u; unsigned

%#o, %#x, and %#X

used to display C prefixes 0, 0x, and 0X

\v

vertical tab; moves the active position to the next vertical tab position

overflow

when a calculation leads to a number too large to be expressed

active position

where the screen cursor doesn't actively move

\\

backslash

\b

backspace; moves the active position back one space on the current line

hexadecimal number represented in c program

base 16 0x or 0X prefix

octal number represented in c program

base 8 0 (zero) prefix

units of computer data or used to describe units of computer memory

bit, byte, and word

signed

can be used with any of the signed types to make your intent explicit.

\r

carriage return; moves the active position to the beginning of the current line.

Nonprinting Characters

characters that are nonprinting.

Floating-point variables

declared and initialized in the same manner as their integer cousins. ex: float noah, jonah; double trouble; float planck = 6.63e-34

Declaring Type char variables

declared in the same manner as other variables char response; char itable, atan;

%x

display an integer in hexadecimal notation

%o

display an integer in octal notation

%hd

displays a short integer in decimal form

%ho

displays a short integer in octal form

The printf() and scanf() functions use the ______ _________________ to indicate how many additional arguments are coming.

first argument ex: printf("%d cats ate %d cans of tuna\n", cats, cans);

3 imaginary variable types

float _Imaginary double _Imaginary long double _Imaginary .

\f

form feed; advances the active position to the start of the next page

%f

format specifier to print type float and double numbers

%ld

format specifier: to print a long value in decimal form

%u

format specifier: to print an unsigned int number

%Lf, %Le, and %La

format specifiers to print the long double type

float toobig

gets assigned a special value that stands for infinity and that printf() displays either inf or infinity

\xhh

hexadecimal value

\t

horizontal tab; moves the active position to the next horizontal tab stop (typically, these are found at character positions 1, 9, 17, 25, and so on).

%c

indicates that a character should be printed

The basic data types are set up using 11 keywords:

int, long, short, unsigned, char, float, double, signed, _Bool, _Complex, and _Imaginary.

unsigned

is used for variables that have only non-negative values. This type shifts the range of numbers that can be stored.

for long long types use

%lld and %llu

for printing unsigned long types

%lu

Why are the hexadecimal numbers and octal numbers better?

- they are powers of 2 - each digit in a hexadecimal number corresponds to exactly 4 bits. -. This correspondence makes it easy to go back and forth between hexadecimal and binary (base 2) notation

float

-The C Standard provides that it must be able to represent at least six significant figures and allow a range of at least 10^-37 to 10^+37

%d

-a format specifier -it indicates the form that printf() uses to display a value -it must be matched by a corresponding int value (int variable, int constant, or any other int value)

a C character constant

-a single character contained between *single quotes* -because characters are really stored as numeric values, you can also use the numerical code to assign values

floating-point numbers

-financial and mathematically oriented programs make use of these numbers. -It is similar to scientific notation.

double type

-for double precision -has the same minimum range requirements as float, but it extends the minimum number of significant figures that can be represented to 10. -typically use 54 bits instead of 32.

long double

-for even more precision than double -C guarantees only that long double is at least as precise as double

word

-the natural unit of memory for a given computer design -a word is just 8 bits -larger word sizes enable faster transfer of data and allow more memory to be accessed.

bit

-the smallest unit of memory -it can hold one of two values: 0 or 1 -the basic building block of computer memory.

Escape sequences

-the special symbol sequences used to represent certain awkward characters in C -must be enclosed in single quotes when assigned to a character variable

byte

-the usual unit of computer memory -for most machines, a byte is 8 bits -But in the C language , there are 256 possible bit patterns of 0s and 1s that can fit in an 8-bit byte.

char type

-used for storing characters such as letters and punctuation marks, but technically it is an integer type. -technically stores integers, not characters. -C language defines a byte to be the number of bits used by type char, so one can have a system with a 16 bit or 32 bit byte and char type.

floating-point number

-what mathematicians call a real number -a number with a decimal point -and e notation

character variable is stored as a ____________________ integer value

1-byte

3 complex variable types

1. float _Complex 2.double _Complex 3.long double _Complex -would contain two float values, one representing the real part of a complex number and one representing the imaginary part.

How to Declare a simple variable

1.Choose the type you need. 2.Choose a name for the variable using the allowed characters 3. Use the following format for a declaration statement: type-specifier variable-name ; The type-specifier is formed from one or more of the type keywords; here are examples of declarations: int erest; unsigned short cash;. 4. You can declare more than one variable of the same type by separating the variable names with commas. Here's an example: char ch, init, ans;. 5. You can initialize a variable in a declaration statement: float mass = 6.0E24;

\a

Alert; produces a beep without moving the screen cursor

subnormal

C refers to floating-point values that have lost the full precision of the type

\"

Double quote (")

Declaring an int Variable

First comes int, and then the chose name of the variable, and then a semicolon. to declare more than one variable, you can follow the int with a list of names in which each name is separated from the next by a comma. int earns; int hogs, cows, goats;

constants

The types of data that are present before a program is used and keep their values unchanged throughout the life of the program

function

a complete and self-containing unit of code that is designed and implemented to perform a specific task.

mantissa

a float number is stored as an exponent and as a value part

integer

a number with no fractional part in C, an integer is never written with a decimal point in C, they are stored as binary numbers

Floating-point constants (literals)

a signed series of digits, including a decimal point, followed by an e or E, followed by a signed exponent indicating the power of 10 used.

NaN

a special floating-point value that can show up: not-a-number

character string

a string of characters enclosed in double quotes

Type int Constants

also called integer constants and integer literals

The _Bool Type

an integer type, that only requires 1 bit of memory, because that is enough to cover the full range from 0 to 1

C automatically expands a type short value to a type int value when it's passed as an _____________________ to a function

argument

the function call printf("Hello,pal") has one __________________. A series of characters in quotes, such as "Hello, pal.", is called a _______________-.

argument; string


Conjuntos de estudio relacionados

S317 Topic 7: Part 2: Stem cells and differentiation

View Set

C743 Data Mining 1 - Terminology

View Set

تعلم شكل وموقع الهمزة المتطرفة والمتوسطة

View Set

Module 1: Introduction to Giza- It's History and Significance

View Set

Unit 2- inflammation causes and treatments

View Set