Operations and C Language

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

What way can I access a header?

#include <header> W., Kernighan Brian; Ritchie Dennis. C Programming Language (p. 241). Pearson Education. Kindle Edition.

EXERCISE EXAMPLE #2: DOB C program

#include <stdio.h> int main() { int a, b, c; printf("Enter the DOB:"); scanf("%d%d%d", &a, &b,&c); printf("The DOB is:%d%d%d",a,b,c); }

printf("%d\t%d\n", fahr, celsius);

%d specifies an integer argument, so the statement causes the values of the two integers fahr and celsius to be printed, with a tab (\t) between them. Each % construction in the first argument of printf is paired with the corresponding second argument, third argument, etc.; they must match up properly by number and type, or you'll get wrong answers.

What are the 4 rules for defining variables?

1. A variable can have alphabets, digits, and underscore. 2. A variable name can start with the alphabet, and underscore only. It can't start with a digit. 3. No whitespace is allowed within the variable name. 4. A variable name must not be any reserved word or keyword, e.g. int, goto , etc.

What are the 2 arguments statements in this printf statement printf("float: %ld \n", sizeof(float));

1. The first is the output string with a format specifier (%ld), 2. The next argument returns the sizeof value.

What basic data types does C language support?

1. int: integer, a whole number. 2. float: floating point, a number with a fractional part. 3. double: double-precision floating point value. 4. char: single character.

how many bits is short

16 bits 32 long

#include <stdio.h> int main() { int a, b; float salary = 56.23; char letter = 'Z'; a = 8; b = 34; int c = a+b; printf("%d \n", c); printf("%f \n", salary); printf("%c \n", letter); return 0; }

42 56.230000 Z

What is the output of the code: 1 #include <stdio.h> 2 3 int main() { 4 int a, b; 5 float salary = 56.23; 6 char letter = 'Z'; 7 a = 8; 8 b = 34; 9 int c = a+b; 10 11 printf("%d \n", c); 12 printf("%f \n", salary); 13 printf("%c \n", letter); 14 15 return 0; 16 }

42 56.230000 Z

What are 15 standard headers?

<assert.h> <float.h> <math.h> <stdarg.h> <stdlib.h> <ctype.h> <limits.h> <setjmp.h> <stddef.h> <string.h> <errno.h> <locale.h> <signal.h> <stdio.h> <time.h>

What is an integer, written as one character within single quotes, such as ′x′?

A character constant

What is a string?

A sequence of characters

What is the value for a declared variable is changed with?

Assignment statement (For example, the following statements declare an integer variable my_var and then assigns it the value 42) int ​my_var; my_var = 42

What are comes and goes with function invocation, does not retain their values from one call to the next, must be explicitly set upon each entry and if they are not set, they will contain garbage?

Automatic Variables

The variables in main, such as line, longest, etc., are private or local to main. No other function can have direct access to them.

Because they are declared within main,

lower = 0; upper = 300; step = 20; fahr = lower; ( print Fahrenheit-Celsius table example)

Computation in the temperature conversion program begins with the assignment statements which set the variables to their initial values. Individual statements are terminated by semicolons.

What indicates the beginning and end of a function (also called a code block

Curly brackets { }

What lists the variables to be used, and state what type they have and perhaps what their initial values are?

Declarations

What may be an explicit extern statement or may be implicit from context?

Declarations

What refers to places where the nature of the variable is stated but no storage is allocated?

Declarations

What refers to the place where the variable is created or assigned storage?

Definition

What combines variables and constants to produce new values?

Expressions

What variable must also be declared in each function that wants to access it; this states the type of the variable

External Variable

What can be used instead of argument lists to communicate data between functions?

External Variables (Explanation: They are globally accessible)

What variable must be defined, exactly once, outside of any function;

External variable

Ture or False: A header need has to be a source file.

False (Explanation: A header need not be a source file.)

const double PI = 3.14;

Fill in the blanks to declare a constant variable PI of type double.

What is the output of this code: #include <stdio.h> int main() { printf("Hello, World!\n"); return 0; }

Hello, World!

What is the output of this code: 1. #include <stdio.h> 2. 3. int main() { 4. printf("Hello, World!\n"); 5. return 0; 6. }

Hello, World!

What does a leading 0x or 0X means?

Hexadecimal

What does the code below do? #include <stdio.h>

Include information about the standard library

What can Octal and hexadecimal constants be followed by to make them long and make them unsigned?

L and U (0XFUL is an unsigned long constant with value 15 decimal)

What does a leading 0 (zero) on an integer constant means

Octal

What can the value of an integer can be specified in?

Octal or hexadecimal instead of decimal.

What specifies what is to be done to declarations

Operators

What does the number 0 generally mean?

Our program has successfully executed Any other number indicates that the program has failed.

Wher are the functions, types and macros of the standard library are declared in?

Standard headers

TRUE OR FALSE: If you haven't botched anything, such as omitting a character or misspelling something, the compilation will proceed silently, and make an executable file called a.out. If you run a.out by typing the command a.out it will print hello, world

TRUE

What is a long constant is written with?

Terminal l (ell) or L, as in 123456789L

What are the three parts within the parentheses of for statements, separated by semicolons? for (fahr = 0; fahr <= 300; fahr = fahr + 20)

The 1st part, the initialization fahr = 0 is done once, before the loop proper is entered. The 2nd part is the test or condition that controls the loop: fahr <= 300 This condition is evaluated; if it is true, the body of the loop (here a single printf) is executed. The 3rd part is the increment step fahr = fahr + 20 is executed, and the condition re-evaluated. The loop terminates if the condition has become false. As with the while, the body of the loop can be a single statement,

celsius = 5 * (fahr-32) / 9; W., Kernighan Brian; Ritchie Dennis. C Programming Language (p. 10). Pearson Education. Kindle Edition.

The Celsius temperature is computed and assigned to the variable celsius by the statement The reason for multiplying by 5 and then dividing by 9 instead of just multiplying by 5/9 is that in C, as in many other languages, integer division truncates: any fractional part is discarded. Since 5 and 9 are integers, 5/9 would be truncated to zero and so all the Celsius temperatures would be reported as zero.

What outputs a newline character and always begin with a backslash \ ?

The \n escape sequence

How does the while loop operate here? while (fahr <= upper) { ... } ( print Fahrenheit-Celsius table example)

The condition in parentheses is tested. If it is true (fahr is less than or equal to upper), the body of the loop (the three statements enclosed in braces) is executed. Then the condition is re-tested, and if true, the body is executed again. When the test becomes false (fahr exceeds upper) the loop ends, and execution continues at the statement that follows the loop. There are no further statements in this program, so it terminates. case, we will always indent the statements controlled by the while by one tab stop

What must begin with either a letter or an underscore and can be composed of letters, digits, and the underscore character?

The name of a variable (also called the identifier)

What function is used to generate output?

The printf function

What indicates the end of the statement?

The semicolon ;

What in the string is C notation for the newline character, which when printed advances the output to the left margin on the next line?

The sequence \n

printf("%3d %6d\n", fahr, celsius);

The simpler one is that the output isn't very pretty because the numbers are not right-justified. That's easy to fix; if we augment each %d in the printf statement with a width, the numbers printed will be right-justified in their fields. For instance, we might say to print the first number of each line in a field three digits wide, and the second in a field six digits wide, like this:

while (fahr <= upper) { ... } ( print Fahrenheit-Celsius table example)

The while loop is used because Each line of the table is computed the same way, so we use a loop that repeats once per output line;

What is the significance of the lines int fahr, celsius; int lower, upper, step; ( print Fahrenheit-Celsius table example)

They are a declaration that announces the properties of variables; it consists of a type name, and a list of variables, The type int means that the variables listed are integers,

True or Fals e Headers may be included in any order and any number of times.

True

True or False : External identifiers that begin with an underscore are reserved for use by the library, as are all other identifiers that begin with an underscore and an upper-case letter or another underscore.

True

True or False: A printf statement can have multiple format specifiers with corresponding arguments to replace the specifiers. Format specifiers are also referred to as conversion specifiers.

True

True or False: C does not have a boolean type.

True

True or False: The C programming language is case-sensitive, so my_Variable and my_variable are two different identifiers.

True

True or False: You can also declare and initialize (assign an initial value) a variable in a single statement: int ​my_var = 42;

True

True or False: You can see, you can declare multiple variables on a single line by separating them with a comma.

True

Ture or False: A header must be included outside of any external declaration or definition and before any use of anything it declares.

True

What are the basic data objects manipulated in a program?

Variables and Constants

3.140000

What is the output of this code:

What do the statements inside the brackets determine?

What the function does when executed.

What is a sequence of characters in double quotes, like "hello, world\n", is called?

a character string or string constant.

What are the The two line /* print Fahrenheit-Celsius table for fahr = 0, 20, ..., 300 */ ( print Fahrenheit-Celsius table example)

a comment, (Explanation: A comment explains briefly what the program does. Any characters between /* and */ are ignored by the compiler)

What do Floating-point constants contain?

a decimal point (123.4) or an exponent (1e−2) or both; their type is double, unless suffixed.

What do the suffixes f or F indicate

a float constant

What do the suffixes l or L indicate?

a long double

What is the size of char

a single byte, capable of holding one character in the local character set.

What are unsigned constants are written with?

a terminal u or U, and the suffix ul or UL indicates unsigned long.

C is a: a. General-purpose programming language b. photo editing program c. Client-side scripting language

a. General-purpose programming language

Which of the following are valid data types in C? a. int, double, char, boolean b. int, bool, string c. int, float, double, char d. int, float, string, char

c. int, float, double, char

Fill In The Blank: Each local variable in a function comes into existence only when the function is __________, and disappears when the function is _________

called excited

What are the data types used in C?

char, int, float, double

What does the code below do? main() {

define a function named main that receives no argument values statements of main are enclosed in braces

What is the size of double?

double-precision floating point.

how many bits is int

either 16 or 32

What command should I enter into the command Terminal to get the to text editor?

gedit

What is an integer constant like 1234 is an?

int

What is the main entry point to a program?

int main() The main() function

What place holders does the scanf function use?

int uses %d float uses %f char uses %c character strings use %s

1. #include <stdio.h> 2. 3. int main() { 4. printf("int: %ld \n", sizeof(int)); 5. printf("float: %ld \n", sizeof(float)); 6. printf("double: %ld \n", sizeof(double)); 7. printf("char: %ld \n", sizeof(char)); 8. 9. return 0; 10. }

int: 4 float: 4 double: 8 char: 1

printf ("hello, world\n");

main calls library function printf to print this sequence of characters; \n represents the newline character

What is the size of int

natural size of integers on the host machine.

Fill in the blanks to output "Hi, everyone!" to the screen: __________("Hi, everyone!")_________

printf ;

What does the below function do? %d

prints as decimal integer

What does the below function do? %6d

prints as decimal integer, at least 6 characters wide

What does the below function do? %f

prints as floating point

What does the below function do? %6.2f

prints as floating point, at least 6 wide and 2 after decimal point

What statement terminates the main( ) function and returns the value 0 to the calling process. T

return 0

What does the simplest application of scanf look like?

scanf("%d", &b);

What is the size of float

single-precision floating point

Fill in the blanks to include the <stdio.h> header. #include < ______________ .h>

stdio

What is the function used for generating output is defined in?

stdio.h

What do I need to include in order to use the printf function?

the header file.

What do variables hold?

values

When does the scanf function stop?

when it exhausts its format string, or when some input fails to match the control specification


संबंधित स्टडी सेट्स

Ch. 15: Managing Marketing Channels and Supply Chains

View Set

Appendix B4 - Joint and conditional distribution

View Set

My review for Business Benchmark

View Set

Chapter 7: Access Control List (NetAcad) (Exam)

View Set

EMT Chapter 27 Quiz - Soft Tissue Injuries

View Set

Leadership Final Exam ch. 14, 18, 19, 25, 6, 17, 5, 7, 27, 26, 31

View Set