Questions tagged [function-declaration]

A function declaration is the process of describing only the return type, argument types, and name of a function. This is required in some programming languages to use functions that were defined at a later point in the code or in another file. Use this tag for questions that pertain to or problems caused by forward declaring functions in languages that support or require doing so.

549 questions
-1
votes
1 answer

How can i make a struct keep the value ive assigned through the function?

Basically I am trying to assign a value to a struct through a function,so that the value that I've assigned is the same on main() afterwards. The struct struct member{ char name; int age; }m1; void assigntostruct(struct member str,int…
kostis14
  • 21
  • 3
-1
votes
1 answer

Changing the sign of array values in C

I need to write a function that takes the elements in an array and changes the sign (ex. 3 --> -3 or -3 --> 3). l want use this array (int a[2][3] = { { 55,-44,},{1, -4},{6,11} };) instead of ( int a[] = { 5,6,-4};) What should I do? #include…
-1
votes
2 answers

Why does this function without a type still work?

Why am I not getting an error even if I declared a function without a type? If the return type is accepted as some types by default, is it healthy to write codes like this? If it already works like this with a compiler feature, then why would we…
noob
  • 107
  • 6
-1
votes
2 answers

Ensure returned pointer is const, without throwing warnings

My goal is to define a clean API for my library. One of my function returns a pointer that shall not be modified with pointers arithmetic. To do so at compile-time, I was planning on using the const keyword in the function prototype. Here's a naive…
gberth
  • 467
  • 5
  • 13
-1
votes
1 answer

Can declaring a function prototype without parameters create security breaches?

I have heard that calling int main(){...} was bad practice and one should rather call the function with its parameters int main(int argc, char* argv[]){...}, I was wondering if this could be generalized to function declarations in headers. In some…
Binou
  • 124
  • 9
-1
votes
3 answers

Can I declare a function in a C source file without declaring it in the header file?

I'm only asking because I have an assignment that includes writing a function to find the inverse of a matrix. I did this using Cramer's rule and a determinant function which I added to my header file. When I submit, however, it uses the header…
Jon D.
  • 27
  • 2
-1
votes
1 answer

Why doesn't it work if I declare the function like this?

I declared the 'GuGuDan' fn in the first place before main fn, but it showed the error message 'Implicit declaration of function 'GuGudan' is invalid in C99' and didn't work. so I tried to find another solution and figured it out it works if I…
-1
votes
1 answer

Perl Subroutine Declaration Unexpected Symbols

I have been looking at some Perl code that has some subroutine declarations that make no sense to me. They appear as: foo($$$$;$); foo(\$\$\$); What do the symbols ";" and "\" do or mean in these declarations?
-1
votes
1 answer

Are all functions inside of an IIFE expressions?

If (function foo(){}) is an expression due to the 'context' as "(Parenthesis)" are a grouping operator and grouping operator can only contain an expression. Which leads to the question, can you declare a function inside of an IIFE or it would still…
-1
votes
2 answers

Swap 2 values of a stack does not work

#include #include using namespace std; #define NMAX 10 // pre-processing directive template class Stack { public: T Smain, Saux; T stackArray[NMAX]; int topLevel; int getTopLevel() { return…
-1
votes
1 answer

Struct as Output of a Function

I wrote this code but when try to compile it, it returns thid error: :24:8: error: conflicting types for ‘safe_syscall’ :19:10: note: previous implicit declaration of ‘safe_syscall’ was here I specified the number of lines. typedef struct syscall…
Peggy
  • 639
  • 9
  • 28
-2
votes
1 answer

how to suppress warnings that C/C++ functions hava no parameters in vscode with clangd?

description I try to use vscode and clangd to write C/C++, but for those functions whose parameters are empty, vscode will give "A function declaration without a prototype is deprecated in all versions of C (fix available)" warnings, looks like…
-2
votes
1 answer

Function with variables in C

Maybe a stupid question, but I don't understood why my program in C works with integers, but not with float. #include main() { float a, b; a = 4.5; b = 9.6; printf("Result of %.2f + %.2f = %.2f", a, b, added_up(a,…
Hermann12
  • 1,709
  • 2
  • 5
  • 14
-2
votes
1 answer

change a var using pointer in a function

#include #include change (int i) { int *x; x = &i; printf("%d\n",*x); *x = 7; printf("%d\n",*x); } int main() { int i=66 ; change(i); printf("%d\n",i); return 0; } I'm wondering how to…
-2
votes
1 answer

What are pointers in C

I have this task: Make corrections in the maxmin.c program so it compiles itself and works correctly (finds max and min out of 3 integer numbers and displays them on the screen). Do not change the structure of the program. In case of incorrect…
bowtie
  • 29
  • 6