A declaration introduces an identifier
and describes its type, be it a type, object, or function. A declaration is what
the compiler needs
 to accept references to that identifier. These are declarations:

extern int bar;
extern int g(int, int);
double f(int, double); // extern can be omitted for function declarations
class foo; // no extern allowed for class declarations

A definition actually instantiates/implements
this identifier. It's what the linker
needs
 in order to link references to those entities. These are definitions corresponding to the above declarations:      [a definition allocate space for the identifier   // myself]

int bar;    [someone said it is not only a definition but also a declaration]
int g(int lhs, int rhs) {return lhs*rhs;}
double f(int i, double d) {return i+d;}
class foo {};

A definition can be used in the place of a declaration.

An identifier can be declared as often as you want. Thus, the following is legal in C and C++:

double f(int, double);
double f(int, double);
extern double f(int, double); // the same as the two above
extern double f(int, double);

However, it must be defined exactly once. If you forget to define something that's been declared and referenced somewhere, then the linker doesn't
know what to link references to and complains about a missing symbols. If you define something more than once, then the linker doesn't know which of
the definitions to link references to and complains about duplicated symbols.

[from website] http://stackoverflow.com/questions/1410563/what-is-the-difference-between-a-definition-and-a-declaration

what is the difference between definition and declaration in c的更多相关文章

  1. Definition vs declaration

    #include <stdio.h> union test1; // declaration union test2 { // The definition of union test2 ...

  2. Relevance Between Variable Declaration and Definition in C++

    A declaration makes a name known to a programm. A definition creates the assocatied entity. A variab ...

  3. Hibernate Validator 6.0.9.Final - JSR 380 Reference Implementation: Reference Guide

    Preface Validating data is a common task that occurs throughout all application layers, from the pre ...

  4. SWIG 3 中文手册——5. SWIG 基础知识

    目录 5 SWIG 基础知识 5.1 运行 SWIG 5.1.1 输入格式 5.1.2 SWIG 输出 5.1.3 注释 5.1.4 C 预处理器 5.1.5 SWIG 指令 5.1.6 解析限制 5 ...

  5. 在centos7(EL7.3 即 kernel-3.10.0-514.X )上安装BCM4312无线网卡驱动要注意的问题

    我新装的centos7主机无法使用里面自带的网卡,查询后发现网卡型号为BCM4312.我在看资料安装的过程中遇到了些问题,纠结了好久,现在分享下要注意的点,为后来的遇到同样问题的人提供点帮助.现在开始 ...

  6. 【转】CentOS6.3安装Broadcom无线网卡驱动

    转自: http://blog.csdn.net/jimanyu/article/details/9697833 下面是具体的步骤 一:确定无线网卡的型号,驱动下载 第一步要确定机子的无线网卡型号是什 ...

  7. clang format 官方文档自定义参数介绍(中英文)

    官方文档:http://clang.llvm.org/docs/ClangFormatStyleOptions.html 中文 在代码中配置样式 当使用 clang::format::reformat ...

  8. [C/C++]C++声明

    [注]本文是Declarations的翻译和注解版. https://msdn.microsoft.com/en-us/library/f432x8c6.aspx 1.声明: 我们通过声明往C++程序 ...

  9. C++ Variables and Basic Types Notes

    1. Type conversion: If we assign an out-of-range value to an object of unsigned type, the result is ...

随机推荐

  1. x265探索与研究(四):怎样编码视频?

    怎样编码视频?           本文介绍x265中的两种编码视频方法,一是採用命令行的方法.二是GUI的方式.   1.命令行的方法   (1).第一种方式生成*.265格式的视频文件       ...

  2. java开发中序列化与反序列化起到的作用

    基本概念: 序列化是将对象状态转换为可保持或传输的格式的过程.与序列化相对的是反序列化,它将流转换为对象. 这两个过程结合起来,能够轻松地存储和数据传输. 特别在网络传输中,它的作用显得尤为重要.我们 ...

  3. html5-8 如何控制html5中的视频标签和音频标签

    html5-8 如何控制html5中的视频标签和音频标签 一.总结 一句话总结:找到视频或者音频的element对象,然后查手册看对应的方法或者属性就可以,里面有控制的. 1.如何控制html5中的视 ...

  4. Linux网络编程——原始套接字实例:MAC 头部报文分析

    通过<Linux网络编程——原始套接字编程>得知,我们可以通过原始套接字以及 recvfrom( ) 可以获取链路层的数据包,那我们接收的链路层数据包到底长什么样的呢? 链路层封包格式 M ...

  5. MySQL慢日志的相关参数

    slow-query-log = on #开启MySQL慢查询功能 slow_query_log_file = /data/mysql/testdb-slow.log #设置MySQL慢查询日志路径 ...

  6. Spring MVC 请求路径遇到的302问题的解决方法

    302 Found 请求的资源现在临时从不同的URI响应请求.由于这样的重定向是临时的,客户端应当继续向原有地址发送以后的请求.只有在Cache-Control或Expires中进行了指定的情况下,这 ...

  7. oracle dual表

    dual是个虚表,其仅仅有一列. 当查询时间或者日期这些对象的时候就须要使用这个表. 比如: select sysdate from dual; 由于在oracle其中,查询语句必需要有keyword ...

  8. jQuery+ localStorage 实现一个简易的计时器

    原型 图片发自简书App 需求1.关闭浏览器时时间继续运行2.刷新时保持当前状态3.结束时间保存在客户端 <div class="wrapper"> <div c ...

  9. Cocos2d-x V3.2+Cocos Studio1.6 实现一个简单的uibutton点击功能

    好久没写博客了 这几天在学习cocos studio,这个软件可以很方便的设计游戏的一些界面,并导入到cocos2dx中,今天就用button来做个样例 首先我们打开Cocos Studio1.6,选 ...

  10. Eclipse使用异常——tomcat启动

    Eclipse使用异常--tomcat启动 一:问题描写叙述 Eclipse刚上手.非常多地方与Myeclipse不一样的地方.比方tomcat的使用.真心的蛋疼. 环境:JDK7.TOMCAT7.E ...