Local scope
The variables defined in the local scope specified block are only visible within the block and not visible outside the block.
Global scope
Global scope specifies that variables defined outside the block are visible until the end of the program.Example
#include<stdio.h> int r= 50; /* global area */ main (){ int p = 30; printf (“p=%d, r=%d” p,r); fun (); } fun (){ printf (“r=%d”,r); }
Output
p =30, r = 50 r = 50
Scope rules related to functions
Functions perform specific tasks statement block.
-
Variables declared within the body of a function are called local variables
These variables exist only inside the specific function that created them. Neither other functions nor the main function know about them
-
The existence of local variables ends when the function completes its specific task and returns to the calling point.
Example
#include<stdio.h> main (){ int a=10, b = 20; printf ("before swapping a=%d, b=%d", a,b); swap (a,b); printf ("after swapping a=%d, b=%d", a,b); } swap (int a, int b){ int c; c=a; a=b; b=c; }
Output
Before swapping a=10, b=20 After swapping a = 10, b=20
Variables declared outside the function body are called global variables. These variables can be accessed through any function.
Example
#include<stdio.h> int a=10, b = 20; main(){ printf ("before swapping a=%d, b=%d", a,b); swap (); printf ("after swapping a=%d, b=%d", a,b); } swap (){ int c; c=a; a=b; b=c; }
Output
Before swapping a = 10, b =20 After swapping a = 20, b = 10
The above is the detailed content of What are the function scoping rules in C programming?. For more information, please follow other related articles on the PHP Chinese website!

我们都知道不是任何数字的平方的数字,如2、3、5、7、8等。非平方数有N个,不可能知道每个数字。因此,在本文中,我们将解释有关无平方数或非平方数的所有内容,以及在C++中查找第N个非平方数的方法。第N个非平方数如果一个数是整数的平方,则该数被称为完全平方数。完全平方数的一些例子是-1issquareof14issquareof29issquareof316issquareof425issquareof5如果一个数不是任何整数的平方,则该数被称为非平方数。例如,前15个非平方数是-2,3,5,6,

我们需要适当的知识才能在C++的数组语法中创建几个唯一的对。在查找唯一对的数量时,我们计算给定数组中的所有唯一对,即可以形成所有可能的对,其中每个对应该是唯一的。例如-Input:array[]={5,5,9}Output:4Explanation:Thenumberofalluniquepairsare(5,5),(5,9),(9,5)and(9,9).Input:array[]={5,4,3,2,2}Output:16寻找解决方案的方法有两种方法可以解决这个问题,它们是−

圆是封闭图形。圆上的所有点到圆内一点的距离都相等。中心点称为圆心。点到圆心的距离称为半径。面积是封闭图形尺寸跨度的定量表示。圆的面积是圆的尺寸内包围的面积。计算圆面积的公式,Area=π*r*r为了计算面积,我们给出了圆的半径作为输入,我们将使用公式来计算面积,算法STEP1:Takeradiusasinputfromtheuserusingstdinput.STEP2:Calculatetheareaofcircleusing, area=(

在本文中,我们将了解逆转算法,将给定的数组向右旋转k个元素,例如−Input:arr[]={4,6,2,6,43,7,3,7},k=4Output:{43,7,3,7,4,6,2,6}Explanation:Rotatingeachelementofarrayby4-elementtotherightgives{43,7,3,7,4,6,2,6}.Input:arr[]={8,5,8,2,1,4,9,3},k=3Output:{4,9,3,8,5,8,2,1}寻找解决方案的方

在本文中,我们将使用C++解决寻找最大值和最小值相同的子数组数量的问题。以下是该问题的示例−Input:array={2,3,6,6,2,4,4,4}Output:12Explanation:{2},{3},{6},{6},{2},{4},{4},{4},{6,6},{4,4},{4,4}and{4,4,4}arethesubarrayswhichcanbeformedwithmaximumandminimumelementsame.Input:array={3,3,1,5,

PHP作为一种非常流行的脚本语言,有着强大的函数库支持,其函数的命名规范和规则对于开发效率和代码可读性都有着重要的影响。本文将介绍PHP函数的命名规范及规则。一、命名风格在PHP中,函数名需要严格符合命名规范和规则,规范主要包括两个方面:命名风格和命名规则。1.下划线命名法下划线命名法是PHP函数命名最常用的方式,也是官方推荐的一种方式。遵循这种方式的函数名

在这个问题中,我们得到一个指向链表头部的指针和一个整数k。在大小为k的组中,我们需要反转链表。例如-Input:1<->2<->3<->4<->5(doublylinkedlist),k=3Output:3<->2<->1<->5<->4寻找解决方案的方法在这个问题中,我们将制定一个递归算法来解决这个问题。在这种方法中,我们将使用递归并使用递归来解决问题。示例#include<iostream&


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
