A

@Adarsh222

2darray

C
2 years ago
#include <stdio.h> /*0, 1, 2 //00 11 22 //02 11 20 3, 4, 5, 6, 7, 8 ==> 0, 2, 4, 6, 8*/ int main() { int n = 0; int m = 0;

array exception imp

C
2 years ago
#include <stdio.h> void out(int *a, int arr[], char *str, int sz){ printf("%d\n",*a); //in C, when you pass an array to a function, it decays into a pointer, and you lose the information //about its size. In this case, you won't be able to calculate the size of the array inside the //function accurately without passing it explicitly //size_t sz = sizeof(arr)/sizeof(arr[0]);

replace word with index manuplate

C
2 years ago
#include <stdio.h> #include <string.h> // Function to find the first occurrence of 'find' in 'str' // Returns the index of the first character of 'find' in 'str' // Returns -1 if 'find' is not found in 'str' int strstrr(char *str, char *find) { char *ffind = find; int index = 0;

replace word

C
2 years ago
#include <stdio.h> #include <string.h> int main() { char input_string[] = "my name adarsh"; char search[] = "name"; char replace[] = "was"; // Find the index of the first occurrence of "name" char *found = strstr(input_string, search);//3

strstr

C
2 years ago
#include <stdio.h> int strstr_custom(const char *haystack, const char *needle) { int index = 0; const char *n = needle; while (*haystack) { const char *h = haystack;//imp Reset the pointers to the current position in the string while (*n && (*h == *n)) {//*h++ or h++ both same

typedef struct

C
2 years ago
#include <stdio.h> typedef struct{ int num; } data; int main() { data d1; d1.num=6; printf("%d",d1.num);

Check how many palindrome words are there

C
2 years ago
#include <stdio.h> #include <string.h> int isPalindrome(const char *str, int start, int end) { while (start < end) { if (str[start] != str[end]) { return 0; // Not a palindrome } start++; end--;

switch

C
2 years ago
The provided code snippet contains a switch statement with a syntax error. The printf("hello"); line is outside the switch block, and it will cause a compilation error. int a = 2; switch (a) { printf("hello");//remember ouside of case se cannot add any print statements code crashes case a: //some stmts

Write your version of memcopy. They would generally write it to make the copy using char, check if t

C
2 years ago
#include <stdio.h> void* my_memcpy(void* dest, const void* src, size_t n) { char* dest_ptr = (char*)dest; const char* src_ptr = (const char*)src; for (size_t i = 0; i < n; i++) { dest_ptr[i] = src_ptr[i]; }

Append and delete the nth node imp

C
2 years ago
#include <stdio.h> #include <stdlib.h> // Define the structure for the linked list node struct Node { int data; struct Node* next; }; // Function to print the linked list

Hex imp code

C
2 years ago
/*Write a C program that takes a hexadecimal number and an integer 'pos' as input. Set 'pos' number of bits from the right to 1 in the given hexadecimal number and print the modified hexadecimal number as the output.*/ #include <stdio.h> int set_all_right_bits(int x, int pos) { for (int i = 0; i < pos; i++) { x = x | (1 << i);//0001 << 1-4 so all becomes 1111 | makes 0,1 to 1 }

Dynamic Memory Allocation and Pointer Usage in C Programming

C
2 years ago
#include <stdio.h> int main() { int* address = (int*)0x12345678; // Replace 0x12345678 with the desired memory address // Write data to the memory address directly *address = 123; // Verify the written data by reading it back using the pointer printf("Value at memory address %p: %d\n", (void*)address, *address);

Struct use in one file to other

C
2 years ago
#include <stdio.h> #include <stdlib.h> #include <string.h> struct Person {//can be written in header file char name[50]; int no; }; void print(struct Person person) {//can be written in header file

Getter setter ex in c

C
2 years ago
#include <stdio.h> //we can name anything for set and get funs since its basic fn not any defined // Private variable static int age; // Getter function int getAge() {// it just return the static value in this file return age;//can can be accesd from all other files

Getter and Setter functions

C
2 years ago
In C, getter and setter functions are used to provide controlled access to variables. They are a way to read and modify the values of variables indirectly, rather than directly accessing them. Here's a simple explanation of getter and setter functions: Imagine you have a variable, let's say age, that you want to make accessible to other parts of your program. Instead of allowing direct access to the age variable, you can create getter and setter functions to retrieve and update its

How can we use a static variable from one file to another

C
2 years ago
No, a static variable defined within a file (also known as file-scope static variable) cannot be accessed directly from another file. The static keyword in C restricts the scope of a variable to the current file only. However, if you need to access a variable from another file, you can use one of the following methods: 1. Function interfaces: Instead of directly accessing the variable, you can define getter and setter functions in the file where the static variable is declared. The

Canvert and modify the value

C
2 years ago
#include <stdio.h> int main() { int hex = 0x10;//0001 0000 int dec = hex;//16 = 10000 binary //1<<2 -> 0000 0001 -> 0000 0100 dec = dec^(1<<4);// 1<<4 means 0001 0000 then 0001 0000 ^ 0001 0000?

IMP To convert hexadecimal to decimal and the modify bits

C
2 years ago
/*Note:- we can modify the or use bitwase operation only on decimal/binary numbers so idf we want to change any bit we can do it in only decimal/binary no so we 1st need to convers hex to decimal/binary and then modify*/ #include <stdio.h> int main() { int hexadecimalNumber = 0x01;//16 int decimalNumber = hexadecimalNumber;// 0000 printf("Before:%d\n",decimalNumber);

Str and Int in one linkedlist

C
2 years ago
#include <stdio.h> #include <stdlib.h> #include <string.h> struct node { int data; char a[10]; struct node* next; };

combine 2 1byte data type into 2byte data type

C
2 years ago
#include <stdio.h> unsigned char a = 0x10;//0001 0000 unsigned char b = 0x20;//0010 0000 int main() { unsigned short data = 0; data = (unsigned short)(a << 8) + b;//binary: 0001 0000 0000 0000 //data = data | b;//0x1020 binary: 0001 0000 0010 0000