Pages

Showing posts with label C programming. Show all posts
Showing posts with label C programming. Show all posts

Sunday, June 16, 2024

What is Static reallocation in C

 During the linker stage, the system has multiple object files to combine and it may be a possibility that some functions might have the same addresses so relocation or changing these addressing during combining the object file is called Static reallocation.

Wednesday, June 5, 2024

MultiLine Macros in C

Macros can be single line as well as multiline

for example :

#define AddMacro(x,y) \
{\
    int total = x + y; \
    printf("%d",total); \
}

In the above example \ is used to tell the compiler to consider the below lines too
if \ is missing then only the first line will be considered as Macro.

Tuesday, June 4, 2024

Toggle a bit in C using XOR

  


int number= 0b11001100;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

}

void loop() {
  // put your main code here, to run repeatedly:
number ^= 1 << 2;
delay(100);
Serial.println(number,BIN);

}



since we count from zero the 3rd last bit will toggle









Sunday, June 2, 2024

What is Stack overflow

  If a program accesses a memory beyond the available limit then a stack overflow occurs and the program gets terminated

Saturday, June 1, 2024

C Language Interview Question:What is the use of "##" operator in C

  #include <stdio.h>

#define concat(a, b) a##b

int main(void)

{

    int yx =7;

    printf("%d\n", concat(y, x));

    printf("%d\n", concat(3, 2));

    return 0;

}

OUTPUT

7

32


EXPLAINATION

the ## operator will concatinate the parameters passed to the macro

In the first case

                            concat(y, x) - the macro will output yx and pass its value to printf as yx is treated as a variable by printf

In the second case

                            concat(3, 2) - the macro will output 32 and printf will print 32 as its treated as an integer


Wednesday, May 29, 2024

What is Segmentation fault

  Segmentation fault is a runtime fault caused due to invalid memory accesses

Segmentation fault can be caused in the following scenarios:

1. When a pointer points to an invalid address

2. When a program tries to access a read-only memory section

3. Freeing a memory which is already freed in the past

Friday, May 24, 2024

C controls- what is the output

  void main()

{

    int a = 2 ;

    float b = 2.0;


    if (a == b)

            printf("Hi");

}


OUTPUT

Hi


Explaination

the variable a is type casted to float before comparison


What is the difference between sexual and asexual reproduction?

Ans: Sexual reproduction takes place by the fusion of two sex cells ( gamates ) that is male and female. Asexual reproduction is a type of r...