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. [PReact] Create a Hello World App with Preact

    By creating a simple ‘hello world’ example application first in vanilla Javascript, and then in Prea ...

  2. pstack.sh 查看进程堆栈

    #!/bin/bash if (( $# < 1 )) then     echo "usage: `basename $0` pid" 1>&2     ex ...

  3. Android自定义组件系列【11】——实现3D立体旋转效果

    今天在网上看到一篇文章写关于Android实现3D旋转(http://www.ibm.com/developerworks/cn/opensource/os-cn-android-anmt2/inde ...

  4. 提高编程能力的7条建议 分类: T_TALENT 2014-04-12 10:41 294人阅读 评论(0) 收藏

    编程是非常酷的一件事情,但是在酷炫的背后它对很多人来说还是挺难的.很多人在学习编程之初就被困难击败了. 当你不熟悉编程的时候,你可能会觉得无从下手,并且不知道如何运用学到的知识.只要你通过了这一困难的 ...

  5. php面试题8

    php面试题8 一.总结 二.php面试题8 1.表单数据提交方式 POST 和 GET 的区别,URL 地址传递的数据最大长度是多少?$_GET 传参是请求 HTTP 协议通过 url 参数传递和接 ...

  6. 摘录-MYSQL5.7版本sql_mode=only_full_group_by问题

    下载安装的是最新版的mysql5.7.x版本,默认是开启了 only_full_group_by 模式的,但开启这个模式后,原先的 group by 语句就报错,然后又把它移除了. 一旦开启 only ...

  7. Docker容器应用日志查看

    原文:Docker容器应用日志查看 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/benben_2015/article/details/80708 ...

  8. PatentTips - Method and system for browsing things of internet of things on ip using web platform

    BACKGROUND The following disclosure relates to a method and system for enabling a user to browse phy ...

  9. 百度echarts可以做什么

    百度echarts可以做什么 一.总结 一句话总结:可视化做的很好,各种图都有.而且支持动态数据. 二.百度eCharts体验 前言 从昨天开始给项目里添加一些图表对比功能,上一个项目里使用的是Hig ...

  10. JS null问题

    在学习getElementById()方法的过程中出现了这样一个问题,便想记录下来. 分析问题之前,我们最好还是先来认识一下getElementById()方法.getElementById()方法, ...