Duplicate
Export
Register
π»
Basic Programming
7 PDFs
14 Flashcard Decks
1 / 1
100%
View
Introduction to Programming with C
Study
What is Computer Programming?
Problem β Algorithms β Source Code β Compiler/Interpreter β Computer Instructions
Interpretation vs. Compilation
Interpretation: Machine code produced at runtimes, more flexibility to change <br> Compilation: Machine code produced once at compilation time, better performance
Computer Programming Languages
A formal language comprising a set of instructions for computer that produce various kinds of output
Why C?
Top popular programming languages, portability, efficiency, memory manipulation, fast, deterministic usage of resources
History of C
1967: BCPL (by Martin Richards): Grandparent of C <br> 1970: B (by Ken Thompson): Parent of C <br> 1972: Traditional C evolved from B (by Denis Ritchie) <br> 1978: The C Programming Language βlanguage reference by Kernighan & Ritchie <br> 1989: ANSI C (by ANSI Committee) <br> 1990: ANSI/ISO C (by ISO Committee) <br> 1999: C99(by Standardization Committee)
1 / 1
100%
View
Basic Programming Flashcards
Study
What is Lecture 2 about?
Topics covered are variables and constants, basic data types, and operators.
What is computer memory?
It includes RAM (Random Access Memory) and RAM segments such as code, data, heap, and stack segments.
What are the basic storage units used in computers?
The basic storage units are bit and byte, where 1 byte equals 8 bits labeled with an address.
What are variables?
Variables are named areas of computer memory used to store values with a scope of validity.
What are the rules for variable names?
Variable names can include letters, digits, underscores, and the first character must be a letter or underscore, while excluding special characters like @, -, *, etc.
What is the scope of a variable?
The scope of a variable refers to where its content can be accessed and manipulated.
What does a variable declaration statement define?
It defines the name, type, and description of the variable.
Why is initial value set after declaring a variable?
To avoid junk value.
How to change a variable?
We use the assignment operation β=β.
What are the basic data types?
The basic data types include int, float, double, char, and void.
What is an integer variable?
An integer variable is any whole number without a decimal point.
How to print out integer variables?
Using the printf() function and %d as integer conversion specification.
What are the ranges of integer variables?
The ranges of integer variables are int: -2147483648 to 2147483647, unsigned int: 0 to 4294967295, signed int: -2147483648 to 2147483647, and short int.
1 / 1
100%
View
Basic Programming Lecture 3 Flashcards
Study
What is structured programming?
It is a programming paradigm aimed at improving the clarity, quality, and development time of a computer program by making extensive use of the structured control flow constructs of selection, repetition, and sequence.
What are the three types of structured control flow constructs?
Selection, repetition, and sequence.
What is a compound statement?
Multiple statements grouped into a block by braces {...}
What is a simple conditional expression?
An expression using relational operators.
What is a combination of simple conditional expressions using logical operators?
A complex expression utilizing logical operators.
What are the relational operators used in C?
<, >, <=, >=, ==, !=
How can boolean data types be used in C?
_Bool and bool
What is the syntax of an if statement?
if(expression)Statement;
What does the basic form of an if statement look like?
ConditionalExpression Statement true false
Basic Programming - Control Flows and Structures
Study
What is the simplest statement in C?
An expression followed by a semicolon.
What are jumping statements in C?
return, break, continue, and goto
What is a compound statement?
Multiple statements grouped into a block by braces {...} that are syntactically equivalent to a single statement
What structures are included in structured programming?
Sequence, conditional branches, and loop
What is a sequential structure in C?
All statements are executed exactly once and in the same order specified in the program
What is a branch structure in C?
Involves conditional or logical expressions or decision making
What is a simple conditional expression in C?
An expression using relational operators that evaluates to either true or false
What is an example of a simple conditional expression in C?
`int a=4; int b=5; if(a<b){printf("You havenohomeworks");}`
What is a basic if statement in C?
A statement used to make decisions with a conditional expression followed by a statement or a series of statements
What is an example of a basic if statement in C?
`if(expression) Statement;`
What are the logical operators in C?
&&,
What is an example of a compound statement in C?
`if(i>0){line[i]=x; x++; i--;}`
1 / 1
100%
View
Flashcards on Basic Programming Functions
Study
- Large problems are broken down into tasks, and those tasks are further broken down into subtasks. Eventually, the subtasks become manageable and implementable in C.<br>- Goal: divide and conquer
A group of statements that perform specific tasks. It has a name to be reused and a goal to divide and conquer. It can return a value or not.
- Keep the main program smaller and easier to read and modify.<br>- Enhance code management.<br>- Reusability.<br>- Reduce repetition code.<br>- Improve readability: makes the main program smaller, and focuses on big points.<br>- Risks of error/bug reduction.<br>- Ease of writing, reading, and debugging the code.
There are two types of function in C:<br>- Built-in functions: are found in standard libraries, for example, printf() and scanf() in <stdio.h>, sqrt(), pow() in <math.h>.<br>- User-defined functions: are defined by the user.
The function declaration is a way to define characteristics of the function before the function is actually called. Syntax: `return_type function_name(parameter_list) { body of the function }`. It defines inputs, outputs, and the body of the function.<br>- Inputs can have arguments and the function can change their values. <br>- Outputs can only have one datatype, which can be void; 0 means good.<br>- The body is a set of statements (in different structures). A function cannot be defined in another function.
It provides input/output functions.
It provides console input/output functions.
It provides general utility functions.
It provides mathematics functions.
It provides string functions.
It provides character handling functions.
It provides date and time functions.
It provides limits of float types.
It provides the size of basic types.
It provides functions to determine the type contained in wide character data.
A set of statements (in different structures) that perform specific tasks.
Flashcards on Basic Programming - Functions
Study
What is the purpose of top-down design in programming?
Top-down design is used to break a large, complex problem down into smaller, manageable tasks.
What are the advantages of using functions in programming?
Functions keep the main program smaller, enhance code management, reduce repetition, and make the code easier to write, read, and debug.
What is the structure of a function in programming?
The structure of a function includes the function name, return type, parameters, function body, and return result.
What are the two types of functions in C?
The two types of functions in C are built-in functions and user-defined functions.
What are some of the standard libraries in C?
Some of the standard libraries in C include stdio.h, math.h, string.h, and ctype.h.
What is the syntax for declaring a function in programming?
The syntax for declaring a function in programming is "return_type function_name(parameter_list) {function_body}".
What are some best practices for defining a function in programming?
Some best practices for defining a function in programming include choosing a meaningful function name, specifying inputs and outputs, and including a contract for the function.
What is an example of a simple function in programming?
An example of a simple function in programming that returns nothing (void) could be defined as follows: "\#include<stdio.h> void functionName(){...}"
1 / 1
100%
View
Basic Programming: Array and String
Study
What is an Array?
A data structure to store a fixed-size sequential collection of elements of the same type.
Why use arrays?
To manage a collection of consecutive individual variables.
How do you declare an array?
`DataType arrayName[arraySize];`
How do you access an element in an array?
Through the array name and the location of the element in the array.
How do you initialize an array?
`DataType arrayName[arraySize] = {element1, element2, ..., elementn};`
What is a 2-dimensional array?
An array with two dimensions or a matrix.
How do you declare and access elements in a 2-dimensional array?
`DataType arrayName[rowSize][columnSize];` and `arrayName[rowIndex][columnIndex];`
What is a 3-dimensional array?
An array with three dimensions.
How do you declare and access elements in a 3-dimensional array?
`DataType arrayName[layerSize][rowSize][columnSize];` and `arrayName[layerIndex][rowIndex][columnIndex];`
Array and String Flashcards
Study
Why do we need arrays?
Arrays are used to store a collection of elements of the same data type. It enables easy manipulation and management of data without having to use individual variables.
What is an array?
An array is a data structure that stores a fixed-size sequential collection of elements of the same type. It allows the manipulation and management of a collection of elements as a single entity.
How do we declare an array?
To declare an array, we need to specify the data type of its elements, a variable name and its size. For 1-dimensional arrays, we use `int A[5];` and for 2-dimensional arrays, we use `int A[3][5];`.
How do we initialize an array in C?
There are two ways to initialize an array in C: (1) by specifying array size during declaration and giving values to each element, like `int A[5] = {1,2,3,4,5};` and (2) by omitting the array size and simply listing the values to be stored, like `int A[] = {1,2,3,4,5};`.
How do we access elements in an array with a loop?
To access elements in a 1-dimensional array with a loop, we can use a `for` loop and specify the index of each element using the array name and the loop variable, like `printf("Element %d in the array is %d \n", i, A[i]);`. To access elements in a 2-dimensional array, we use a nested loop, like `for(int i=0;i<2;i++){for(int j=0;j<3;j++){printf("\n A[%d][%d]:%d", i, j, A[i][j]);}}`.
Basic Programming: Array and String
Study
What is an array?
An array is a data structure storing a fixed-size sequential collection of elements of the same type.
What is the definition of an array?
A data structure storing a fixed-size sequential collection of elements of the same type.
How do you declare a 1-D array in C?
`int A[5];`
How do you declare a 2-D array in C?
`int A[3][5];`
How do you initialize an array in C?
`int A[5] = {1, 2, 3, 4, 5};`
How do you access an element in a 1-D array in C?
To access an element, you should define the array name and the location of the element in the array `A[i]`.
How do you access an element in a 2-D array in C?
To access an element, you should define the array name and two locations of the element in the array `A[i][j]`.
What is the role of an array name in C?
An array name is a pointer to the first element of the array.
What is a string in C?
Strings are a sequence of characters in memory followed by the null character '\0'.
How do you initialize and print a string in C?
Initialize a string like `char text[] = "Hello World";` and print it with `printf("%s", text);`.
What is the fgets() function in C?
The fgets() function reads at most one less than the number of characters specified by size from the given string and stores them in the string str.
What are some common string library functions in C?
`strlen()`, `strcpy()`, `strcat()`, and `strcmp()`.
C Programming: Arrays and Strings
Study
What is the value at index `[1][2]` in the memory area below?
`A`
How can arrays be passed as arguments to functions?
By value or by reference
What is a string?
An array of characters terminated by '\0'
How is a string declared in C?
`char str[10] = "Hello";`
How is individual characters of a string accessed?
Using the array subscript notation, like `str[1]`
What are some of the string manipulation library functions in C?
`strcpy()`, `strcat()`, `strlen()`, `strcmp()`
1 / 1
100%
View
Flashcards on Pointers in Basic Programming
Study
What is a pointer?
A variable that contains the memory address of another variable
What is the address of a variable?
The specific location where a variable is stored in memory
What is the contents of a variable pointed by the pointer?
The value stored in the memory location that the pointer is pointing to
What is the syntax for pointer declaration?
`Type * pointer name;`
What is the syntax for pointer initialization?
`Type* pointer_name = &variable_name;`, `Type* pointer_name = NULL;`
How do you access a value through a pointer?
Using the `*` operator
How do you pass pointers to functions?
Declare function parameters as pointer type
How do you return pointers from functions?
Declare function return type as a pointer type
What are void pointers?
Pointers that can point to other variables of any type
What are pointers to constants?
Pointers that point to a value that must not be changed
What are constant pointers?
Pointers whose address stored in the pointer cannot be changed, but the value pointed by the constant pointer can be changed
1 / 1
100%
View
Flashcards: Basic Programming - Data Structures and File I/O.
Study
What is a structure in programming?
A user-defined data type that combines a limited number of data elements into a unified data unit.
What is an example of a structure?
A record about a book in a library with properties such as title, author, subject, book ID, and publishing year.
How do you declare a struct?
By specifying its data elements in arbitrary types using the `struct` keyword: `struct Book { char* title; char* author; char* subject; char* ID; int year; };`.
How do you declare a struct variable?
By specifying the type of the struct and the name of the variable: `struct Book fiction1;`.
How do you initialize a struct?
By assigning values to its data elements using curly braces: `struct Book fiction1 = {"Harry Potter", "JKRowling", "fiction","Fi123", 2005};`.
How do you access a member of a struct?
Using the dot `.` operator: `fiction1.title = "Harry Potter";`.
What is the `typedef` keyword used for?
To give a shorter name for the struct, making it easier to declare variables: `typedef struct Book bk; bk fiction1;`.
How do you calculate the size of a struct?
By using the `sizeof` operator: `printf("Size of book struct is %lu\n", sizeof(Book));`.
Can struct variables be compared?
No.
Can members of struct variables be compared?
Yes.
How do you declare an array of structs?
By specifying the type of the struct and the size of the array: `Book fiction[5];`.
How do you access elements of an array of structs?
By using the dot `.` operator and the index of the element: `fiction[1].title = "The Lord of the Rings";`.
Data Structures and File I/O in Basic Programming
Study
What is a structure?
A user-defined data type that combines a limited number of data elements into a unified data unit.
What is the syntax for declaring a struct?
`struct Book { char* title; char* author; char* subject; char* ID; int year; };`
How do you declare a struct variable?
`struct Book fiction1;`
How do you initialize a struct?
Declare the variable and assign values to each attribute, e.g. `struct Book fiction1 = { "Harry Potter", "JKRowling", "fiction", "Fi123", 2005 };`
How do you access a member of a struct?
Use the "." operator, e.g. `fiction1.title`
What is the purpose of `typedef` with structs?
To give a shorter name for the struct, e.g. `typedef struct Book bk; bk fiction1;` or `typedef struct { char* title; char* author; char* subject; char* ID; int year; } Book; Book fiction2;`
How do you declare an array of structs?
`Book fiction[5];`
What is the size of a struct?
The size of a struct can be found using the `sizeof()` function, e.g. `printf("Size of book struct is %lu\n", sizeof(Book));`
C Programming Flashcards
Study
What is a programming language?
A set of rules, conventions, and instructions for writing software programs.
What is a compiler?
A software that translates the code written in some high-level programming language (like C) into machine language (the language that can be understood by the computer).
What is a variable?
A named memory location that stores a value of a specific type.
What is a function?
A set of instructions that performs a specific task or a group of tasks.
What is an array?
An ordered collection of elements of the same type.
What is a loop?
A repeating set of instructions.
What is a conditional statement?
A statement that performs different actions depending on whether a condition is true or false.
What is a pointer?
A variable that stores the memory address of another variable.
What is an algorithm?
A set of well-defined instructions for solving a problem or a task.
What is recursion?
A technique in which a function calls itself to solve a subproblem.
What is a data structure?
A way of organizing and storing data in a computer program.
What is dynamic memory allocation?
A way of allocating memory dynamically during program execution.
What is a linked list?
A data structure in which each element contains a reference (i.e., a link) to the next element in the sequence.
What is a stack?
A data structure in which elements are inserted and removed from only one end.
What is a queue?
A data structure in which elements are inserted at one end and removed from the other end.
Scholarly Assistant's Insights
A beginner-friendly introduction to computer programming with C, covering key concepts and language benefits.
Programming
Technology
Java
Software Development
Flashcards
Ask Scholarly Assistant
Similar Pages
Login to Leave a Comment
Give your feedback, or leave a comment on a page to share your thoughts with the community.
Login