C programming language

 0    34 flashcards    guest2139848
download mp3 print play test yourself
 
Question English Answer English
How can we determine the specific size of a particular data type?
start learning
You need to use sizeof operator. It returns the size in bytes of its operand. you can use printf(“Size od int: %zu bytes\n”, sizeof(int));
How do we put the header files of other modules or libraries into the source file od the program?
start learning
we use #include “header_file_name. h” if the header file is in the same directory as source file. From standard library we can include like #include <stdio. h>
How do we approach data fields of the composite data type (struct) in C?
start learning
We use the dot. operator It allows to access individual members of the struct. Such as struct Person {char name[50]; int age;}; int main() {person1. age = 30;} We can also use pointers to structs in that case use arrow operator -> instead dot
Describe how the function int doit(int r) is called and how are the data passed to it.
start learning
When function is called the program execution jumps to the functions definition, executes the statements inside function and the returns control to point in the program immedietaly following function call
How do you dynamically allocate memory for storing a sequence of 20 values of the data type int?
start learning
We use malloc function from library <stdlib. h>. We declare a pointer to an integer int *sequence to hold the address. We use malloc for an areat of 20 integers sequence = (int *) malloc(20 * sizeof(int)); Then we check if memory allocation was succesful
How do you increase a dynamic array to save ten more items?
start learning
Allocate new memory using realloc and copy existing data from old array to the new. Then free memory and update the pointer
What is the NULL identifier?
start learning
Its a null pointer constant typically defined as an integer constant zero. Its purpose is to indicate that a pointer does not point to any memory location. It usually indicates the end of a list. For example when alloc of memory fail Null returned
How are text strings represented in C?
start learning
For that we use arrays of characters, terminated by a null character ‘\0’ Those are C-strings. char str[6] = {‘h’, ’e’, ’j’} or using string literals char str[] = “Hej”; In this case compiler add the null chracter automatically at the end of the string
What represents the void type?
start learning
Its a special keyword used to indicate the absence of type. It can be used in several contexts: Function does not return any value void name(parameters), Function doesnt accept parameters void name(void), generic pointers can point to any datatype void *p
Explain the difference between the variable and the pointer to a variable.
start learning
holds values directly vs hold memory addresses; accesed directly by names vs dereferenced; modifying changes the value vs memory address; pointers allow dynamkc memory alloc but require dereferencing
What are the characters used in C for output control?
start learning
newline character \n; horizontal tab character \t; Backspace character \b; carriage return character \r
How to get a pointer to a variable defined as double d = 12.3;
start learning
Declare a pointer of type double * and assign the address of the variable d to it using the address-of operator %. double d = 12.3; double *ptr; ptr = &d
How is the pointer and array [] different?
start learning
dynamic memory vs static; dont know size and length vs arrays know that; can be incremented and decremented vs not; need to be explicitly initialized to point to address vs can be initialized with initial values
What is the difference between a pointer to a constant and a constant pointer?
start learning
A pointer to a constant (const int *ptr) allows modification of the pointer itself but not the value it points to. A constant pointer (int *const ptr) allows modification of the value it points to but not the pointer itself. Both concepts are useful
Define a variable length array s of the size n, which is provided as a command line argument?
start learning
int main(int argc, char *argv[]) {int n = atoi(argv[1]); int *s = (int *) malloc(n * sizeof(int));
Describe briefly the struct type used in C.
start learning
It allows to group together one or more variables of diff data types under single name. example: struct Person {char name[50]; int age;};
What C compilers do you know?
start learning
GCC the most widely used available on multiple platforms; Clang excellent diagnostics known for fast compilation speed
Describe the process of creating an executable program from the C source files.
start learning
Writing source code; compilation; each source file produces object file; linking libraries; executing program
Explain the difference between the variable and the pointer to a variable?
start learning
While variables store values directly and are accesed by their names, pointers store memory addresses of variables and allow indirect access to their values. Pointers provide additional flexibility and functionality especially in terms of memory mamagemen
Does const in the variable definition guarantee that it cannot change?
start learning
While const provides a level of immutability and helps prevent unintended modifications to variables, it does not offer complete protecion against all. It can be changed with pointers indirectly, but it may make program behavior unpredictable
For what is the keyboard ‚do’ used
start learning
Part of the do while loop structure it allows to repeatedly execute a block of cide whjle a specified condition is true, with the condition checked after each iteration. do {things} while (count < 5)
For what is the keyword ‚while’ used?
start learning
while (count < 5) {things}
For what is the keyword ‚for’ used?
start learning
For loop, initalization, condition and update. for (int i = 0; i < 5; i++) {things}
keyword if
start learning
conditional statements evaluated true or false
Keyword case
start learning
various possible execution paths based on the value of an expression. switch (option) {case 1: things case 2: things default: things}
Keyword switch
start learning
Used to create multi way branch statement which allows you to select one of many code blocks to be executed based on the value of an expression
Keyword break
start learning
used to exit from a loop or switch statement prematurely terminates the innermost liop kr switch in which is contained
How do you create a pointer to a variable such ad int?
start learning
declare the pointer assign the address example: int num = 10; int *ptr; ptr = &num;
What is the program return value that indicates a succesful execution and why?
start learning
Its typically zero. Due to clarity, convention, compatibility with shell scripts, error reporting, and consistency
How do you dynamically allocate memory in C.
start learning
You can use malloc(), calloc(), or realloc() which are part of stdlib.h. You also need to free it after all
How do you release dynamically allocated memory in c
start learning
its released using free() function. always do it to prevent memory leaks.
Define the diagonal matrix 3x3 as a 2D int array
start learning
int diaginal[3][3] = {{1,0,0},{0,1,0},{0,0,1}};
Whats a difference between a thread and a process
start learning
share resources vs isolated; communicate through shared memory vs require ipc mechanisms; lower creation and context switching of threads; failure affect other threads vs does not
What is critical section?
start learning
part of programs code that must be executed by only one process or thread at a time. Its a region of code where shared resources are accesed and manipulated and concurrent acess by multiple process or threads could lead to incorrect results

You must sign in to write a comment