Questions tagged [c]

Programming questions are off-topic here. Do not ask questions about how to write code in C. However, conceptual questions about computer science are more appropriate. See our help center for the scope of this site.

Filter by
Sorted by
Tagged with
1 vote
0 answers
37 views

How do i make a 2d array as same as i possibly can with another one?

Say i have an 2d array A of nxn size, int values already given for each item.these values can be the same or different. There's gonna be another nxn array B being input. I can only interchange one row ...
HelpmePlease's user avatar
0 votes
1 answer
34 views

What is the reason or advantage of having special purpose status flags for the result of comparisons? [duplicate]

The C semantics treat the result of a comparison or any true/false operation as just an int ...
user16217248's user avatar
0 votes
1 answer
33 views

What is the purpose of padding bits in primitive integer types?

The C standard carves out room for implementations which have padding bits in their integer types. Padding bits affect the size of an integer but not the number of possible values they can contain. I ...
user16217248's user avatar
1 vote
2 answers
66 views

Why is `3[arr]` notation of accessing elements in array is not used?

Today, I came across the notation 3[arr] in C++, and I was surprised to find out that it's a valid way to access array elements. For example: ...
tbhaxor's user avatar
  • 128
0 votes
2 answers
36 views

finding wrong elements in a descending sorted array using binary search

i have this question where im given a an array that contains the distance of a traveler from a certain destination at the i-th time of the day. ideally the array should be in descending order but the ...
user1188938's user avatar
0 votes
1 answer
105 views

Requirements to a CPU architecture to actually allow a C compiler to be built for it

I have this rather weird CPU architecture for which currently only an assembler exists. I won't go into too much details about this architecture as it is not publicly available. However, some quirks ...
GNA's user avatar
  • 121
0 votes
0 answers
39 views

I want to get into Operating Systems, where do I start?

I have been doing web/app development for a few years, primarily involving high-level programming and stuff. However, I am interested in jumping into some low-level stuff and genuinely understanding ...
Ryan Wang's user avatar
  • 101
0 votes
1 answer
51 views

How to visualize 1 pixel?

The CS50 course by Edx that I am pursuing has this statement in their Week 4 practice set: A 24-bit BMP file, then, is essentially just a sequence of bits, (almost) every 24 of which happen to ...
Splendid Digital Solutions's user avatar
0 votes
0 answers
23 views

Shell algorithm knuth sequence time complexity analysis

Given this shell sort algorithm implementation: ...
Kim's user avatar
  • 1
0 votes
0 answers
20 views

Problems with writing short job first algorithm(for scheduling of processes) in C language

Hy everyone. I'm trying to write the SJF (short job first) algorithm NON-PREEMPTIVE for scheduling processes in C. I want to implement an algorithm that orders some processes by the burst of the ...
Enri's user avatar
  • 1
0 votes
1 answer
47 views

Help with time complexity of a given code

Given the following code: ...
complexity's user avatar
6 votes
4 answers
3k views

How does the linker know where to look for a function implementation in C++?

I am currently learning about how the compilation and linking works in C++. I think I kinda get how the compiler works, and that for a file to fully compile you don't need to have function ...
artas2357's user avatar
  • 163
1 vote
1 answer
49 views

Upper limit of instructions of a program for a Turing machine that has been converted from a real programming language

Imagine that I have an algorithm written in C that is of, let's say, 10,000 characters in length. Such a program can be simulated on a turing machine (Wikipedia: Anything a real computer can compute, ...
CasseroleBoi's user avatar
5 votes
3 answers
2k views

automatic memory allocation

Global variables are given fixed addresses in main memory by the C compiler, called static memory allocation. Function local variables are created on the stack, this is called automatic memory ...
DanielJackson1's user avatar
-1 votes
1 answer
135 views

Does the Posix read() system call for FILE* have an internal buffer in the kernel?

Does the answer depend on the number of bytes requested? If it is forced to keep a buffer due to some unknown device/diver, can it optimize and skip the buffer if it's going to be a disk read? I'm ...
estin's user avatar
  • 1
10 votes
10 answers
6k views

In C, why limit || and && to evaluate to booleans?

In some languages, e.g. Ruby, an expression like: val = call_fn() || DEFAULT_VAL; will set val to the results of call_fn() if ...
fearless_fool's user avatar
0 votes
1 answer
166 views

how to get the high 32-bit of the answer of two 32-bit integer multiple?

Recently, I study the instruction set of riscv32 and face a order as "mulh" which tends to multiply two 32-bits signed integers and store the high 32 value into the register. And here comes ...
Ecthelion's user avatar
0 votes
1 answer
1k views

BNF and EBNF Syntax for while loops in C#

Given the programming language C#, how would I be able to write the BNF and EBNF grammar syntax of its while loop? After trying to search and understand more, I got this as my BNF grammar for while ...
Randomguy's user avatar
0 votes
0 answers
28 views

How to merge both, mutable and immutable worlds?

In the ideal world, systems are designed using immutable data structures. However, when you dive deeper into lower levels of abstractions, you realize that at some point a library written in C is ...
Yulio Granja's user avatar
1 vote
1 answer
148 views

Is it true that everything is a side effect in C?

I'm just a beginner, I've started learning programming, CS, math, and Unix. I know how to code in Pascal and also study C. In the university a professional programmer, who teaches coding, said that ...
George Glebov's user avatar
0 votes
0 answers
38 views

How to calculate how many times a function inside a for loop inside a while loop will be called?

I'm studying for my exams and a came through this exercise but I can't prove the result I found. Given this piece of code: ...
Nikolas P.'s user avatar
1 vote
0 answers
36 views

How to decide row / column strides for a loop over a matrix get these cache hit rates?

Given CPU with: L1 cache: 4-ways, block size = 32 bytes , cache size = 64KB , LRU (Cache replacement policy). L2 cache: 2-ways, block size = 32 bytes , cache size = 512KB , LRU (Cache replacement ...
JobProcessTask's user avatar
1 vote
2 answers
81 views

Questions about compilers and machine code

When it is said that machine code is specific to a machine, is it specific to an architecture, or is it specific to a machine? Do two identical processors require different machine code? My guess is ...
prss98408's user avatar
1 vote
4 answers
458 views

Why is C still the fastest? Critique my take

A friend and I were surprised that C still has near-best performance among languages. I thought about why this is, and I wrote up a few paragraphs. I wonder if the friendly folks on CS stack could ...
Eric Auld's user avatar
  • 115
0 votes
1 answer
327 views

Difference between bits and bytes?

What are bits and bytes? How do they differ? What role do these notions play in the computer science world? Why do talk about 8 bits = 1 byte = 256 states or different patterns? What's the rationale ...
Vinay Sharma's user avatar
0 votes
0 answers
46 views

What is bit (or binary digit)?

So, if I were to represent 23 in binary, what are bits here? Are 0 and 1 called bits? What they mean when they say I have five bits of information?
Vinay Sharma's user avatar
-1 votes
1 answer
340 views

What does zsh: suspended ./a.out mean? [closed]

I was writing a program to count lines from an input text stream. This is the program. It compiles perfectly but when I execute ./a.out to get the output my ...
kraanasgard's user avatar
3 votes
2 answers
771 views

What are pointers in low-level language like C

I was trying to understand pointers by watching YouTube videos. However, I could not understand How do they work? Why do we use them? When do we use them?
salluc 1's user avatar
1 vote
1 answer
679 views

C: iterate over a unicode (utf-8/utf-16) string, conditionally modify individual characters, and store it as new string [closed]

C's char array can hold an ASCII string, such that a user can query individual characters by indexing the char array, modify them or do what ever they want to, its pretty straight forward. I have ...
codepoet's user avatar
  • 111
2 votes
4 answers
1k views

Why was the fast inverse square root algorithm so ingenious?

In 2005 ID software open source the game Quake 3 Arena. When they did it was discovered was an algorithm that was so ingenious and all it did was calculate the inverse of a square root. The easy way ...
Neil Meyer's user avatar
1 vote
2 answers
3k views

How C++ and alike maps are actually stored in memory?

I admit I didn't know much before what a Map is living with just the terminology Hash Tables, even when I first Google it I found this https://www.mathworks.com/help/matlab/matlab_prog/overview-of-the-...
ShAr's user avatar
  • 138
-4 votes
1 answer
260 views

Must a partial halt decider be a pure function of its inputs?

Must a partial halt decider be a pure function of its inputs? A partial halt decider correctly decides the halt status of some of its inputs. I am trying to write C code that would be acceptable to ...
polcott's user avatar
  • 87
-1 votes
1 answer
448 views

Checksum Algorithm that produces correct 16-bit checksum value for any given input

I need a checksum algorithm that produces the correct 16-bit checksum value for a given input. It's a packet recording from serial communication that I would like to reverse engineer. I have two data ...
user141929's user avatar
2 votes
3 answers
183 views

Why doesn't the compiler typecast the pointer and remove the error? (C++ Programming)

int *numPtr; double num; numPtr = # This code shows an error as pointer points to data of different datatype. But why does it show the error? Why doesn't ...
Kshitij's user avatar
  • 21
0 votes
1 answer
271 views

Pointers and Dereference Operator

*a = *b In C, the above expression is always interpreted as the assignment of the value at the address contained in b to the value at an address in a. But, according to the precedence of operators and ...
Aman Rathore's user avatar
6 votes
1 answer
1k views

How are extremely large integers stored and implemented in programming languages?

We have data types like int and long etc. which can store just a few bytes of integers. But when we are implementing ...
Yuv's user avatar
  • 139
2 votes
0 answers
1k views

What assigns the physical addresses to variables?

Earlier I was having a technical test when I stumbled across this question: I know that probably in modern systems, the OS and the MMU is responsible for that. But the test was focused on Embedded ...
Amr Mohamed's user avatar
-7 votes
2 answers
488 views

Simulating Halt Decider Applied to the Halting Theorem

A key breakthrough is that the author of the best selling book on the theory of computation MIT professor Michael Sipser has agreed that the following verbatim paragraph is correct: If simulating halt ...
polcott's user avatar
  • 87
-9 votes
1 answer
606 views

Are the halting problem proofs refuted by software engineering?

Can D simulated by H terminate normally? The x86utm operating system based on an open source x86 emulator. This system enables one C function to execute another C function in debug step mode. When H ...
polcott's user avatar
  • 87
0 votes
2 answers
389 views

Find offset and page number given paged virtual memory address

I ran into this question in class: Assume a machine that is 64-bit and has 8GB memory. They use a paged virtual memory where the page size is 4KB. You run the following program: ...
Melanie's user avatar
  • 103
0 votes
1 answer
200 views

Combinations (repetition not allowed & order not important)

How to compute a table of numbers (all possibilities), where repetition is not allowed and order is not important. Example: I have a set of prime numbers. In this example I have four: {3,5,7,11}, but ...
Natural Number Guy's user avatar
3 votes
1 answer
145 views

Why is the address-of operator in C/C++ represented with the "&" symbol?

I've started learning C++, and I know a little bit of C. Something that always struck me as somewhat off was that the address-of operator is represented with the seemingly random ampersand (&) ...
Nat H's user avatar
  • 31
0 votes
0 answers
67 views

How to help compiler do pipelining?

I don't mean compiler flags for pipelining. I would like to program in a way that helps the compiler do optimizations using pipelining. I mean I want to order instructions in C in such a way that GCC (...
Alejandro Arcila's user avatar
2 votes
2 answers
1k views

How are kernels (and operating systems in general) written in C?

I'm trying to understand how you set about writing an OS in something like C. I've always used C to write applications - using commands like malloc and ...
MysteriousWaffle's user avatar
0 votes
0 answers
419 views

matrix product openMP code in C runs slower in parallel than series

If I start with 4 threads when I run my code and increase thread number each time I run it, my run time decreases as you would expect. However, my run time for 1 thread is significantly smaller than ...
Robin's user avatar
  • 1
1 vote
1 answer
36 views

What is the correct algorithm to see whether N points lie on the same side of a line?

What I tried first was to find the equation of the line and then compare its y-intercepts with the y-intercepts of each point. I just need the proper approach to this algorithm.
sohamb172's user avatar
  • 115
-1 votes
1 answer
40 views

Find the most frequent alphabet appearing in the given string. In case letter with same frequency, choose the one which comes first alphabetically

This is the desired result which I want:
sohamb172's user avatar
  • 115
2 votes
1 answer
47 views

printf("%d",~5); prints out -6 why is that?

I was reading the book "Computer systems: A programmer's perspective" and saw that the operator, "~", is a NOT operator. When I use it to NOT positive integers, it returns the ...
Bekalu Tilahun's user avatar
-1 votes
1 answer
54 views

doubts on cin and scanf [closed]

i spent literally 5hrs trying to figure out, why the value of n is 1 for my second test case ( which begins at line 12 ) , but i am unable to, could you help me with that? ...
user127167's user avatar
0 votes
1 answer
283 views

How to Sort 2D array with out 1D array

Hello I am a new Computer Science student Ok, so I am trying to sort the 2D array I know you can actually sort a 2D array by copying it into a 1D array sort it using any Algorithm, and then place ...
DeathNet123's user avatar