C programming language

 0    34 speciālā zīme    guest2139848
lejupielādēt mp3 Drukāt spēlēt pārbaudiet sevi
 
jautājums English atbilde English
How can we determine the specific size of a particular data type?
sākt mācīties
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?
sākt mācīties
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?
sākt mācīties
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.
sākt mācīties
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?
sākt mācīties
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?
sākt mācīties
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?
sākt mācīties
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?
sākt mācīties
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?
sākt mācīties
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.
sākt mācīties
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?
sākt mācīties
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;
sākt mācīties
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?
sākt mācīties
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?
sākt mācīties
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?
sākt mācīties
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.
sākt mācīties
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?
sākt mācīties
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.
sākt mācīties
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?
sākt mācīties
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?
sākt mācīties
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
sākt mācīties
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?
sākt mācīties
while (count < 5) {things}
For what is the keyword ‚for’ used?
sākt mācīties
For loop, initalization, condition and update. for (int i = 0; i < 5; i++) {things}
keyword if
sākt mācīties
conditional statements evaluated true or false
Keyword case
sākt mācīties
various possible execution paths based on the value of an expression. switch (option) {case 1: things case 2: things default: things}
Keyword switch
sākt mācīties
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
sākt mācīties
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?
sākt mācīties
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?
sākt mācīties
Its typically zero. Due to clarity, convention, compatibility with shell scripts, error reporting, and consistency
How do you dynamically allocate memory in C.
sākt mācīties
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
sākt mācīties
its released using free() function. always do it to prevent memory leaks.
Define the diagonal matrix 3x3 as a 2D int array
sākt mācīties
int diaginal[3][3] = {{1,0,0},{0,1,0},{0,0,1}};
Whats a difference between a thread and a process
sākt mācīties
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?
sākt mācīties
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

Lai ievietotu komentāru, jums jāpiesakās.