C Programming Midterms Reviewer PDF

Summary

This document is a review of C programming concepts. It includes topics such as bitwise operators, comma operators, and the sizeof operator. It also explores the conditional ternary operator and provides an overview of C programming fundamentals.

Full Transcript

# BITWISE OPERATORS | Operators | Meaning of operators | |---|---| | & | Bitwise AND | | \| | Bitwise OR | | ^ | Bitwise exclusive OR | | ~ | Bitwise complement | | << | Shift left | | >> | Shift right | ### COMMA OPERATOR -> used to link related expressions together int a, c = 5, d; ### THE SIZ...

# BITWISE OPERATORS | Operators | Meaning of operators | |---|---| | & | Bitwise AND | | \| | Bitwise OR | | ^ | Bitwise exclusive OR | | ~ | Bitwise complement | | << | Shift left | | >> | Shift right | ### COMMA OPERATOR -> used to link related expressions together int a, c = 5, d; ### THE SIZEOF OPERATOR -> sizeof is an unary operator that returns the size of data | data | Size | |---|---| | int | 4 bytes | | float | 4 bytes | | double | 8 bytes | | char | 1 byte | | integer type array having 10 elements | 40 bytes| ### C TERNARY OPERATOR -> conditional operator is ternary operator, works on 3 operands ### CONDITIONAL OPERATOR SYNTAX conditionalExpression ? expression1: expression2 The conditional operator works as follows: * The first expression conditionalExpression is evaluated first. This expression evaluates to 1 if it's true and evaluates to 0 if it's false. * If conditionalExpression is true, expression1 is evaluated. * If conditionalExpression is false, expression2 is evaluated. # COMPUTER PROGRAMMING MIDTERMS REVIEWER ## scanf() -> function reads formatted input from the keyboard -> if user enters an integer it will be stored in variable testinteger -> the "&" sign before testinteger; &testinteger gets the address of testinteger and the value is stored in that address ## In (NEWLINE) -> single character called newline ## return 0; -> return statement returns value from main OS -> return value is important as it tells the OS whether the program succeeded or not -> return value of 0 means success ## getchar(); -> waits user to hit enter thus prevents the window from closing ## ; (SEMICOLON) -> indicate that the statement ends ## CHARACTER SET -> set of alphabets, letters and some special characters ## ALPHABETS -> could be uppercase or lowercase ## DIGITS -> numbers (0, 1, 2, 3...) ## SPECIAL CHARACTERS -> <, >, &, #, ?, \(, \), [, ]... ## WHITE SPACE CHARACTERS -> blank space, new line -> horizontal tab, carriage return and form feed ## C KEYWORDS -> pre defined, reserved words used in programming language that have special meanings -> keywords are part of syntax and cannot be used as identifier -> auto, double, int, struct, break, else, long, switch, float, const... ## C IDENTIFIERS -> name given to entities such as variables, functions structures... -> must be unique e.g 'int money;" "double accountBalance" ## RULES FOR IDENTIFIERS -> a valid integer can have letters, digits and underscores. The first letter should be either a letter or underscore but discouraged to use Identifier names with underscore. No rule on length however the first 31 characters are discriminated ## PRACTICE -> choose any name for identifier except for the keywords ## VARIABLES -> container to hold data -> symbolic representation of a memory location ## RULES FOR VARIABLES -> variables can only have letters, digits and underscore. The first letter should be either letter or underscore but discouraged to use name identifiers with underscore as it can cause error. No rule however the first 31 letters are checked so it should be different ## CONSTANTS/LITERALS -> value that is cannot be altered in a program ### DIFFERENT TYPES OF CONSTANTS 1. **INTEGER (Int)** -> whole number, real numbers without fraction or exponent * **DECIMAL CONSTANT (BASE 10)** -> 0, -9, 22.. * **OCTAL CONSTANT (BASE 8)** -> starts with 0 e.g 021, 077, 033... * **HEXADECIMAL CONSTANT (BASE 16)** -> starts with 0x e.g 0x7f, 0x2a 2. **FLOATING POINT CONSTANTS** -> numeric constant that has either fractional form or exponent 3. **CHARACTER CONSTANTS** -> uses a single quotation (') around characters 'a' 4. **ESCAPE SEQUENCE** -> characters which cannot be typed or has special meanings -> In new line, \b backspace, \f form feed, \r return, It horizontal tab, \v vertical tab, 1 backslash, \' single quotation, " double quotation, \? question mark, \0 null character 5. **STRING CONSTANTS** -> constants enclosed in a double quotation (") 6. **ENUMERATION CONSTANTS** -> used to define enumeration types enum color (yellow, green, black, white); ## INTEGER (int) -> integers but no decimal values e.g 0, -5.. ## FLOATING (float) -> can hold real numbers, 6 digits (4 bytes) e.g 2.34 ## DOUBLE (double) -> double precision, 14 digits bytes ## CHARACTER (char) -> declaring character that uses a (") ## STRING (string) -> series of characters surrounded by (") ## C QUALIFIERS -> alter meanings of base data types to yield a new data type ### SIZE QUALIFIERS -> can alter the size, long and short long double i; ### SIGN QUALIFIERS -> int and float can hold negative and positive integers, if positive value only unsigned data types are used // unsigned variables cannot hold negative value unsigned int positiveInteger; ### CONSTANT QUALIFIERS -> identifier can be declared constant const int cost = 20; ### VOLATILE QUALIFIERS -> variable should be declared volatile if its value can be changed by some external sources ## C ARITHMETIC OPERATORS -> mathematical operations such as addition, subtraction & multiplication on numerical values (constants and variables) ### INCREMENT OPERATORS -> ++, Increase the value by 1 ### DECREMENT OPERATORS -> --, decrease the value by 1 ## C ASSIGNED OPERATORS | Operator | Example | Same as | |---|---|---| | = | a = b | a = b | | += | a += b | a = a + b | | -= | a -= b | a = a - b | | *= | a *= b | a = a * b | | /= | a /= b | a = a / b | | %= | a %= b | a = a % b | ## C RELATIONAL OPERATORS | Operator | Meaning of Operator | Example | |---|---|---| | == | Equal to | 5 == 3 returns 0 | | > | Greater than | 5 > 3 returns 1 | | < | Less than | 5 < 3 returns 0 | | != | Not equal to | 5 != 3 returns 1 | | >= | Greater than or equal to | 5 >= 3 retums 1 | | <= | Less than or equal to | 5 <= 3 retum 0 | ## C LOGICAL OPERATORS | Operator | Meaning of Operator | Example | |---|---|---| | && | Logical AND. True only if all oprands are true | if c 5 and d 2 then, expression (c == 5) && (d > 5) equals to 0 | | \|\| | Logical OR. True only if either one operand is true | if c 5 and d 2 then, expression (c == 5) || (d > 5) equals to 1 | | ! | Logical NOT. True only if the operand is 0 | If c 5 then, expression !(c == 5) equals to 0 | ## TERMINATOR (OVAL) -> beginning or end ## DATA (PARALLELOGRAM) -> input or output ## PROCESS (RECTANGLE) -> step to be carried out ## DECISION (DIAMOND) -> decision point between 2 or more options ## PRE DEFINED PROCESS (DOUBLE LINE RECTANGLE) -> marker for another process step ## DINAMIC/DYNAMIC CONNECTOR -> show direction of process flow ## PSEUDOCODE -> english like nonstandard language -> allows more precision but less in syntax -> not executable on a computer ->e.g "set total to zero," "get list of numbers" ## C -> general purpose programming language -> developed by Dennis Ritchie at Bell Lab in 1972 -> first used as the system language for UNIX OS ### KEN THOMPSON -> is the developer of the UNIX -> evolved from B to BCPL ### B -> assembler and used by KT to produced the initial version of UNIX in 1970 ### BCPL -> Martin Richard in 1967, typeless programming language ## ANSI C (STANDARD C) -> American National Standard Institute -> mature general purpose language widely available on machines and OS -> chief industrial programming language of the world -> found in colleges and universities ### FOUNDATION FOR C++ -> object oriented ## OPERATING SYSTEM -> provides software for the user -> act as interface between user and hardware ## HOW TO WRITE & RUN C PROGRAM 1. FIND A COMPILER * for windows: IDE (DEV C++), GCC * for android: Cxxdroid ### COMPILER -> translates source code to object code that's executable 2. TYPE THE CODES IN A TEXT EDITOR * notepad++ or DEV C++ 3. SAVE YOUR FILE IN.C EXTENSION 4. COMPILE AND RUN ## FUNCTION -> collection of commands that say "do something" ### #include<stdio.h> -> #include causes the processor to include a copy of the header stdio.h at this point in the code -> >> is the angle brackets that indicates that the file is to be found in the usual place ### int main (void) -> tells that there's function named main and it returns an integer -> vold indicates that the function takes no arguments ### {} (CURLY BRACES) -> signal the beginning and end of functions ## printf() -> standard C way of displaying output on the screen -> controls what gets printed ### printf modifiers | Modifier | Meaning | |---|---| | %c | character | | %d | integer | | %e | float value in scientific notation | | %f | float value | | %lf | double float value | | %s | string | ## COMPUTER -> any device capable of processing data into information ## PROGRAM -> list of instructions to process data into information ## PROGRAMMING -> procedure of developing detailed instructions -> act of instructing computer to perform task called coding ## PROGRAMMING LANGUAGE -> set of syntax for instructing computer to perform specific tasks ## HIGH LEVEL LANGUAGE -> written that is close to human language like C, C++, Java Script -> easier to modify, faster to write, easier to debug because it uses english like sentences -> portable code but not designed on just one type of machine ## LOW LEVEL LANGUAGE -> written for specific architecture and hardware -> closer to binary and hard to understand (assembly language/machine code) -> special machine dependent instructions -> can be translated into program that requires less memory -> write code that can be executed faster ## SYNTAX -> grammatical rules of programming language ## SYNTAX ERROR -> character sequence error -> prevents the program from compiling or running until error is corrected ## LOGIC ERROR -> stops the program from performing as intended -> bug or mistake in the source code, wrong formula ## DEBUGGING -> process of identifying and removing errors from a program ### (1) PUZZLE SOLVER -> involves trial and error and patience ### (2) ALWAYS LEARNING -> requires constant learning and skill updating to stay competitive and successful ### (3) CURIOUS -> always seeks to understand the functionality of their work ### (4) SELF DISCIPLINED -> often in their zone, maintaining this deep work requires self discipline -> maintaining a confortable environment ### (5) COMMUNICATION SKILLS -> excellent written and communication skills ### (6) ADAPTABLE -> capable of adapting to changes ### (7) LOGICAL MINDSET -> excels in problem solving through analytical and logical mindset ### (8) LOVE FOR TECHNOLOGY -> passionate about the technology ## 5 STEPS PROCESS OF PROGRAMMING 1. **DEFINING THE PROBLEM** -> identifying the problem as well as the input and the output 2. **PLANNING THE SOLUTION** -> two methods for this is the flowchart and pseudocode or both 3. **CODING** -> code the program -> translate the logic into programming language 4. **TESTING** -> debugging 5. **DOCUMENTING** -> comprehensive written of the cycle, detailing specific program ## PROGRAM LOGIC FORMULATION -> step by step development of solution to a problem ## ALGORITHM -> step by step method using natural language and a recipe like approach -> step 1, step 2, step 3 and so on ## FLOWCHART -> pictorial representation of the step by step process -> developed by ANSI as standard set of symbols

Use Quizgecko on...
Browser
Browser