Thread: error: expected declaration specifiers or '...' before numeric constant

  1. #1
    Registered User
    Join Date
    Dec 2014
    Posts
    13

    Post error: expected declaration specifiers or '...' before numeric constant

    Hi All,

    Below is my code ... Please explain why am I getting the below error.

    Thanks in advance..!

    Code:
    #include <stdio.h>
     
    
    int main(){
     void ptostruct(int );
      void ptostruct(5);
     
    }
    
    void ptostruct(int i){
     printf("displaying");
    }

    error is below

    Code:
     error: expected declaration specifiers or '...' before numeric constant

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    This is a declaration of a function named ptostruct that takes an int argument and has a return type of void:
    Code:
    void ptostruct(int );
    This is a syntax error since 5 is not a type name:
    Code:
    void ptostruct(5);
    You probably wanted to call the function:
    Code:
    ptostruct(5);
    By the way, there is no need to leave out the parameter name in the declaration. Just write:
    Code:
    void ptostruct(int i);
    This can even be pretty convenient when you copy and paste from the function definition.

    Also, why place the function declaration in the main function body? It is more typical to place it at file scope, like the function definition.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2014
    Posts
    13
    Thanks again LaserLight ... !!!

    Understood Clearly ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. expected identifier before numeric constant
    By Elixz in forum C Programming
    Replies: 14
    Last Post: 05-31-2012, 06:13 AM
  2. Error: expected declaration or statement at end of input
    By ebyrne288 in forum C Programming
    Replies: 2
    Last Post: 11-15-2011, 05:31 PM
  3. Replies: 3
    Last Post: 04-28-2011, 11:27 PM
  4. Replies: 13
    Last Post: 09-22-2007, 12:07 PM
  5. Declaration of constant-compiler error
    By Noah in forum C Programming
    Replies: 1
    Last Post: 10-10-2001, 10:05 PM