Questions tagged [function-definition]

Use this tag for questions specifically about the rules, syntax, or behavior of function definitions but not for questions that happen to have code with function definitions in them but are not about function definitions.

Only use this tag if the issue at hand is about or related to the function definition.

A function definition is the definition of a user defined function along with the code the function contains. This is distinct from which only defines the name and arguments of a function in certain programming languages. Example in C:

void SayHello(void); // Function declaration

void SayHello(void) { // Function definition
    puts("Hello world!");
}

Some languages do not have function declarations and only have function definitions. Example in JavaScript:

function SayHello() { // Function definition; no forward declaration is required in JavaScript
    console.log("Hello world!")
}

Function definitions are very common in programming. Many questions will contain them, but only use this tag if they are part of the question, and not just part of code being used to demonstrate an unrelated problem. Consider using other tags in these cases:

  • Use if the question is about functions in general.
  • Use if the question is about forward declarations of functions and not about defining the code of the function.
963 questions
2
votes
3 answers

move node from one linked list to another in certain conditions

I have a question that I am stuck with for a couple of days, and I need some help. I have a function called splitList. The function needs to remove nodes from the original list and move them to a new list only if the previous node and the next node…
ezra
  • 87
  • 1
  • 1
  • 7
2
votes
2 answers

inline keyword causes linker error in Clion

I have a strange error concerning the inline keyword, this is just a sample code I wrote: #include #include uint8_t inline LIB_MATH_BTT_u8GetMSBSetBitPos(uint32_t args_u32Variable) { uint8_t local_u8MSBSetBitPos = 0; …
abdo Salm
  • 1,678
  • 4
  • 12
  • 22
2
votes
1 answer

Leetcode medium problem (Singly Linked lists)

1561/1563 test cases passed problem discription: You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contains a single digit. Add the two numbers and…
2
votes
1 answer

What are the correct types for memset function?

On trying to recreate "memset" function I have error if I try to dereference a void pointer, or have a different type for the second argument than the first. To make the function work I had to change it to: void ft_memset(unsigned char *st, unsigned…
2
votes
1 answer

Why conditionally compile an obsolete K&R definition versus standard C definition?

I came across this code in the wild and got very confused. #ifdef __STDC__ double cos(double x) #else double cos(x) double x; #endif { // ... } I fail to see why the latter in the #else would be preferable in any circumstances. Are…
user16217248
  • 3,119
  • 19
  • 19
  • 37
2
votes
2 answers

string copy() function return misunderstood? (C)

(EDIT) Probable misunderstanding in updating and returning a string from a function in C. I'm a student and have just started trying out dynamic memory allocation techniques. Recently, I was told to work on a string copy() function similar to the…
IICN-08
  • 23
  • 5
2
votes
2 answers

Issues with Linked List in C

The prompt I was given asks for a program in c that implements a linked list and gives users options to perform different functions on the linked list. The needed functions are: isempty(): checks if the list is empty and returns values indicating…
2
votes
3 answers

Binary search algorithm using `size_t` instead of using `int`

This is the binary search algorithm from Wikipedia. It uses int type indexing. The use of the int type here is necessary because the algorithm sometimes uses the negative index values while searching. int binary_search(unsigned array[], int length,…
NoSkill
  • 718
  • 5
  • 15
2
votes
2 answers

Using functions to lesser repetitiveness

I have been working on this problem for a while now: basically I need to put the for loop in a function so I can call for it, but I don't how to to make a function return a 2D array, I want to solve this by creating a 1D array, but the problem is…
2
votes
3 answers

type-agnostic belongs function

I'm trying to build a function that checks whether a particular pointer value is stored in a given array. I'm trying to make the function type-agnostic and so I decided to go with the approach that was used to implement qsort(), in which a function…
Mehdi Charife
  • 722
  • 1
  • 7
  • 22
2
votes
5 answers

Modifying a function without losing sense

Edit: I think I need to be more precise, the code itself is good but I need to modify it not to have a block with more than 3 branches. For instance, one could separate it by doing multiple functions I am trying to do the Fizzbuzz, my code is right…
2
votes
2 answers

My find-biggest-number Recursive function returns a discremented value

I have a problem in this recursive function that basically takes two numbers and returns the biggest one of them without using comparison (> || < ) operators, thing is, it returns dicremented values even though I held the starting values in a…
2
votes
2 answers

Changing the variable assigned as a pointer to the parameter in C

Firstly I'm using C language. I want a variable that I refer to as a parameter to change outside the function when it is changed inside the function. But the problem is that the variable is of type linked list and I want to add to the linked…
2
votes
2 answers

Overloading the arithmetic operators using friend functions

I found an example of how to overload arithmetic operators using friend functions, and the overloaded operator function is defined inside the class with comments stating that: /* This function is not considered a member of the class, even though the…
2
votes
1 answer

How to use toupper library function in C?

I need to print the initials of a name, like tyler jae woodbury would print TJW, but I can't seem to print the uppercase initials. This is my code: #include #include #include #include string…
Tyler
  • 21
  • 2