/
Basic Programming
Save to my account
Sign up
Made with Scholarly
·
Turn your own files into flashcard decks like this
Sign up
đ»
Basic Programming
View
Introduction to Programming with C
Study
1
Question
What is Computer Programming?
Answer
Problem â Algorithms â Source Code â Compiler/Interpreter â Computer Instructions
2
Question
Interpretation vs. Compilation
Answer
Interpretation: Machine code produced at runtimes, more flexibility to change <br> Compilation: Machine code produced once at compilation time, better performance
3
Question
Computer Programming Languages
Answer
A formal language comprising a set of instructions for computer that produce various kinds of output
4
Question
Why C?
Answer
Top popular programming languages, portability, efficiency, memory manipulation, fast, deterministic usage of resources
5
Question
History of C
Answer
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)
View
Basic Programming Flashcards
Study
1
Question
What is Lecture 2 about?
Answer
Topics covered are variables and constants, basic data types, and operators.
2
Question
What is computer memory?
Answer
It includes RAM (Random Access Memory) and RAM segments such as code, data, heap, and stack segments.
3
Question
What are the basic storage units used in computers?
Answer
The basic storage units are bit and byte, where 1 byte equals 8 bits labeled with an address.
4
Question
What are variables?
Answer
Variables are named areas of computer memory used to store values with a scope of validity.
5
Question
What are the rules for variable names?
Answer
Variable names can include letters, digits, underscores, and the first character must be a letter or underscore, while excluding special characters like @, -, *, etc.
6
Question
What is the scope of a variable?
Answer
The scope of a variable refers to where its content can be accessed and manipulated.
7
Question
What does a variable declaration statement define?
Answer
It defines the name, type, and description of the variable.
8
Question
Why is initial value set after declaring a variable?
Answer
To avoid junk value.
9
Question
How to change a variable?
Answer
We use the assignment operation â=â.
10
Question
What are the basic data types?
Answer
The basic data types include int, float, double, char, and void.
11
Question
What is an integer variable?
Answer
An integer variable is any whole number without a decimal point.
12
Question
How to print out integer variables?
Answer
Using the printf() function and %d as integer conversion specification.
13
Question
What are the ranges of integer variables?
Answer
The ranges of integer variables are int: -2147483648 to 2147483647, unsigned int: 0 to 4294967295, signed int: -2147483648 to 2147483647, and short int.
View
Basic Programming Lecture 3 Flashcards
Study
1
Question
What is structured programming?
Answer
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.
2
Question
What are the three types of structured control flow constructs?
Answer
Selection, repetition, and sequence.
3
Question
What is a compound statement?
Answer
Multiple statements grouped into a block by braces {...}
4
Question
What is a simple conditional expression?
Answer
An expression using relational operators.
5
Question
What is a combination of simple conditional expressions using logical operators?
Answer
A complex expression utilizing logical operators.
6
Question
What are the relational operators used in C?
Answer
<, >, <=, >=, ==, !=
7
Question
How can boolean data types be used in C?
Answer
_Bool and bool
8
Question
What is the syntax of an if statement?
Answer
if(expression)Statement;
9
Question
What does the basic form of an if statement look like?
Answer
ConditionalExpression Statement true false
Basic Programming - Control Flows and Structures
Study
1
Question
What is the simplest statement in C?
Answer
An expression followed by a semicolon.
2
Question
What are jumping statements in C?
Answer
return, break, continue, and goto
3
Question
What is a compound statement?
Answer
Multiple statements grouped into a block by braces {...} that are syntactically equivalent to a single statement
4
Question
What structures are included in structured programming?
Answer
Sequence, conditional branches, and loop
5
Question
What is a sequential structure in C?
Answer
All statements are executed exactly once and in the same order specified in the program
6
Question
What is a branch structure in C?
Answer
Involves conditional or logical expressions or decision making
7
Question
What is a simple conditional expression in C?
Answer
An expression using relational operators that evaluates to either true or false
8
Question
What is an example of a simple conditional expression in C?
Answer
`int a=4; int b=5; if(a<b){printf("You havenohomeworks");}`
9
Question
What is a basic if statement in C?
Answer
A statement used to make decisions with a conditional expression followed by a statement or a series of statements
10
Question
What is an example of a basic if statement in C?
Answer
`if(expression) Statement;`
11
Question
What are the logical operators in C?
Answer
&&,
12
Question
What is an example of a compound statement in C?
Answer
`if(i>0){line[i]=x; x++; i--;}`
View
Flashcards on Basic Programming Functions
Study
1
Question
- 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
Answer
2
Question
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.
Answer
3
Question
- 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.
Answer
4
Question
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.
Answer
5
Question
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.
Answer
6
Question
It provides input/output functions.
Answer
7
Question
It provides console input/output functions.
Answer
8
Question
It provides general utility functions.
Answer
9
Question
It provides mathematics functions.
Answer
10
Question
It provides string functions.
Answer
11
Question
It provides character handling functions.
Answer
12
Question
It provides date and time functions.
Answer
13
Question
It provides limits of float types.
Answer
14
Question
It provides the size of basic types.
Answer
15
Question
It provides functions to determine the type contained in wide character data.
Answer
16
Question
A set of statements (in different structures) that perform specific tasks.
Answer
Flashcards on Basic Programming - Functions
Study
1
Question
What is the purpose of top-down design in programming?
Answer
Top-down design is used to break a large, complex problem down into smaller, manageable tasks.
2
Question
What are the advantages of using functions in programming?
Answer
Functions keep the main program smaller, enhance code management, reduce repetition, and make the code easier to write, read, and debug.
3
Question
What is the structure of a function in programming?
Answer
The structure of a function includes the function name, return type, parameters, function body, and return result.
4
Question
What are the two types of functions in C?
Answer
The two types of functions in C are built-in functions and user-defined functions.
5
Question
What are some of the standard libraries in C?
Answer
Some of the standard libraries in C include stdio.h, math.h, string.h, and ctype.h.
6
Question
What is the syntax for declaring a function in programming?
Answer
The syntax for declaring a function in programming is "return_type function_name(parameter_list) {function_body}".
7
Question
What are some best practices for defining a function in programming?
Answer
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.
8
Question
What is an example of a simple function in programming?
Answer
An example of a simple function in programming that returns nothing (void) could be defined as follows: "\#include<stdio.h> void functionName(){...}"
View
Basic Programming: Array and String
Study
1
Question
What is an Array?
Answer
A data structure to store a fixed-size sequential collection of elements of the same type.
2
Question
Why use arrays?
Answer
To manage a collection of consecutive individual variables.
3
Question
How do you declare an array?
Answer
`DataType arrayName[arraySize];`
4
Question
How do you access an element in an array?
Answer
Through the array name and the location of the element in the array.
5
Question
How do you initialize an array?
Answer
`DataType arrayName[arraySize] = {element1, element2, ..., elementn};`
6
Question
What is a 2-dimensional array?
Answer
An array with two dimensions or a matrix.
7
Question
How do you declare and access elements in a 2-dimensional array?
Answer
`DataType arrayName[rowSize][columnSize];` and `arrayName[rowIndex][columnIndex];`
8
Question
What is a 3-dimensional array?
Answer
An array with three dimensions.
9
Question
How do you declare and access elements in a 3-dimensional array?
Answer
`DataType arrayName[layerSize][rowSize][columnSize];` and `arrayName[layerIndex][rowIndex][columnIndex];`
Array and String Flashcards
Study
1
Question
Why do we need arrays?
Answer
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.
2
Question
What is an array?
Answer
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.
3
Question
How do we declare an array?
Answer
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];`.
4
Question
How do we initialize an array in C?
Answer
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};`.
5
Question
How do we access elements in an array with a loop?
Answer
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
1
Question
What is an array?
Answer
An array is a data structure storing a fixed-size sequential collection of elements of the same type.
2
Question
What is the definition of an array?
Answer
A data structure storing a fixed-size sequential collection of elements of the same type.
3
Question
How do you declare a 1-D array in C?
Answer
`int A[5];`
4
Question
How do you declare a 2-D array in C?
Answer
`int A[3][5];`
5
Question
How do you initialize an array in C?
Answer
`int A[5] = {1, 2, 3, 4, 5};`
6
Question
How do you access an element in a 1-D array in C?
Answer
To access an element, you should define the array name and the location of the element in the array `A[i]`.
7
Question
How do you access an element in a 2-D array in C?
Answer
To access an element, you should define the array name and two locations of the element in the array `A[i][j]`.
8
Question
What is the role of an array name in C?
Answer
An array name is a pointer to the first element of the array.
9
Question
What is a string in C?
Answer
Strings are a sequence of characters in memory followed by the null character '\0'.
10
Question
How do you initialize and print a string in C?
Answer
Initialize a string like `char text[] = "Hello World";` and print it with `printf("%s", text);`.
11
Question
What is the fgets() function in C?
Answer
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.
12
Question
What are some common string library functions in C?
Answer
`strlen()`, `strcpy()`, `strcat()`, and `strcmp()`.
C Programming: Arrays and Strings
Study
1
Question
What is the value at index `[1][2]` in the memory area below?
Answer
`A`
2
Question
How can arrays be passed as arguments to functions?
Answer
By value or by reference
3
Question
What is a string?
Answer
An array of characters terminated by '\0'
4
Question
How is a string declared in C?
Answer
`char str[10] = "Hello";`
5
Question
How is individual characters of a string accessed?
Answer
Using the array subscript notation, like `str[1]`
6
Question
What are some of the string manipulation library functions in C?
Answer
`strcpy()`, `strcat()`, `strlen()`, `strcmp()`
View
Flashcards on Pointers in Basic Programming
Study
1
Question
What is a pointer?
Answer
A variable that contains the memory address of another variable
2
Question
What is the address of a variable?
Answer
The specific location where a variable is stored in memory
3
Question
What is the contents of a variable pointed by the pointer?
Answer
The value stored in the memory location that the pointer is pointing to
4
Question
What is the syntax for pointer declaration?
Answer
`Type * pointer name;`
5
Question
What is the syntax for pointer initialization?
Answer
`Type* pointer_name = &variable_name;`, `Type* pointer_name = NULL;`
6
Question
How do you access a value through a pointer?
Answer
Using the `*` operator
7
Question
How do you pass pointers to functions?
Answer
Declare function parameters as pointer type
8
Question
How do you return pointers from functions?
Answer
Declare function return type as a pointer type
9
Question
What are void pointers?
Answer
Pointers that can point to other variables of any type
10
Question
What are pointers to constants?
Answer
Pointers that point to a value that must not be changed
11
Question
What are constant pointers?
Answer
Pointers whose address stored in the pointer cannot be changed, but the value pointed by the constant pointer can be changed
View
Flashcards: Basic Programming - Data Structures and File I/O.
Study
1
Question
What is a structure in programming?
Answer
A user-defined data type that combines a limited number of data elements into a unified data unit.
2
Question
What is an example of a structure?
Answer
A record about a book in a library with properties such as title, author, subject, book ID, and publishing year.
3
Question
How do you declare a struct?
Answer
By specifying its data elements in arbitrary types using the `struct` keyword: `struct Book { char* title; char* author; char* subject; char* ID; int year; };`.
4
Question
How do you declare a struct variable?
Answer
By specifying the type of the struct and the name of the variable: `struct Book fiction1;`.
5
Question
How do you initialize a struct?
Answer
By assigning values to its data elements using curly braces: `struct Book fiction1 = {"Harry Potter", "JKRowling", "fiction","Fi123", 2005};`.
6
Question
How do you access a member of a struct?
Answer
Using the dot `.` operator: `fiction1.title = "Harry Potter";`.
7
Question
What is the `typedef` keyword used for?
Answer
To give a shorter name for the struct, making it easier to declare variables: `typedef struct Book bk; bk fiction1;`.
8
Question
How do you calculate the size of a struct?
Answer
By using the `sizeof` operator: `printf("Size of book struct is %lu\n", sizeof(Book));`.
9
Question
Can struct variables be compared?
Answer
No.
10
Question
Can members of struct variables be compared?
Answer
Yes.
11
Question
How do you declare an array of structs?
Answer
By specifying the type of the struct and the size of the array: `Book fiction[5];`.
12
Question
How do you access elements of an array of structs?
Answer
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
1
Question
What is a structure?
Answer
A user-defined data type that combines a limited number of data elements into a unified data unit.
2
Question
What is the syntax for declaring a struct?
Answer
`struct Book { char* title; char* author; char* subject; char* ID; int year; };`
3
Question
How do you declare a struct variable?
Answer
`struct Book fiction1;`
4
Question
How do you initialize a struct?
Answer
Declare the variable and assign values to each attribute, e.g. `struct Book fiction1 = { "Harry Potter", "JKRowling", "fiction", "Fi123", 2005 };`
5
Question
How do you access a member of a struct?
Answer
Use the "." operator, e.g. `fiction1.title`
6
Question
What is the purpose of `typedef` with structs?
Answer
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;`
7
Question
How do you declare an array of structs?
Answer
`Book fiction[5];`
8
Question
What is the size of a struct?
Answer
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
1
Question
What is a programming language?
Answer
A set of rules, conventions, and instructions for writing software programs.
2
Question
What is a compiler?
Answer
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).
3
Question
What is a variable?
Answer
A named memory location that stores a value of a specific type.
4
Question
What is a function?
Answer
A set of instructions that performs a specific task or a group of tasks.
5
Question
What is an array?
Answer
An ordered collection of elements of the same type.
6
Question
What is a loop?
Answer
A repeating set of instructions.
7
Question
What is a conditional statement?
Answer
A statement that performs different actions depending on whether a condition is true or false.
8
Question
What is a pointer?
Answer
A variable that stores the memory address of another variable.
9
Question
What is an algorithm?
Answer
A set of well-defined instructions for solving a problem or a task.
10
Question
What is recursion?
Answer
A technique in which a function calls itself to solve a subproblem.
11
Question
What is a data structure?
Answer
A way of organizing and storing data in a computer program.
12
Question
What is dynamic memory allocation?
Answer
A way of allocating memory dynamically during program execution.
13
Question
What is a linked list?
Answer
A data structure in which each element contains a reference (i.e., a link) to the next element in the sequence.
14
Question
What is a stack?
Answer
A data structure in which elements are inserted and removed from only one end.
15
Question
What is a queue?
Answer
A data structure in which elements are inserted at one end and removed from the other end.