c語言指針中and
1. &在c語言中什麼意思
主要有兩個意思:
取地址符,用在指針表達式或輸出變數地址時 例如 int a; &a就是表示變數a在內存中地址
二進制位與位運算符 1&1=1 0&0=0
拓展資料:
C語言主要特點:
C語言是高級語言。它把高級語言的基本結構和語句與低級語言的實用性結合起來。C 語言可以像匯編語言一樣對位、位元組和地址進行操作,而這三者是計算機最基本的工作單元。
C語言是結構式語言。結構式語言的顯著特點是代碼及數據的分隔化,即程序的各個部分除了必要的信息交流外彼此獨立。這種結構化方式可使程序層次清晰,便於使用、維護以及調試。C 語言是以函數形式提供給用戶的,這些函數可方便的調用,並具有多種循環、條件語句控製程序流向,從而使程序完全結構化。
C語言功能齊全。具有各種各樣的數據類型,並引入了指針概念,可使程序效率更高。而且計算功能、邏輯判斷功能也比較強大。
C語言適用范圍大。適合於多種操作系統,如Windows、DOS、UNIX、LINUX等等;也適用於多種機型。 C語言對編寫需要硬體進行操作的場合,明顯優於其它高級語言,有一些大型應用軟體也是用C語言編寫的。
2. C語言指針問題
#include<stdio.h>
intmain(){
voidmaxandmin(int*data,int*max,int*min,intlen);
intarr[10],max,min,len=10,i;
for(i=0;i<10;i++)
scanf("%d",arr+i);
maxandmin(arr,&max,&min,len);
printf("max=%d,min=%d ",max,min);
return0;
}
voidmaxandmin(int*data,int*max,int*min,intlen){
inti;
*max=*min=*data;
for(i=1;i<len;i++){
if(*(data+i)>*max)*max=*(data+i);
if(*(data+i)<*min)*min=*(data+i);
}
}
3. C語言中:&&和||符號是什麼意思
「&&」表示
與,意為同時都要滿足。
「||」表示
或,意為二者或多著只要滿足其中一個。
在C語言中,&&和||都屬於邏輯運算符,並且都是雙目運算符。
邏輯運算符總共有3個,分別是"&&"、"||"和"!"。a
&&
b,一假必假,結合性從左至右。||是邏輯或運算符,a
||
b,一真必真,結合性從左至右。
&&和||在Java和PHP以及c#中都是邏輯操作符,也叫條件操作符。
(3)c語言指針中and擴展閱讀
:
c語言中&&是一種雙目運算符,表示與運算,而當左邊所給表達式或變數為0時,不再計算右
側,整個表達式為零。
邏輯運算符是用來判斷一件事情是"成立"還是「不成立」,或者說是「真」還是「假」,判斷的結果只有兩個值,用數字表示就是「0」和「非0」。
其中,「非0」表示該邏輯運算的結果是「真」,「0」表示這個邏輯運算表達式的結果為「假」。
參考資料:
搜狗網路-&&
搜狗網路-||
4. C語言中一個指針問題
不同。*(++p)是先讓p向後移一單元再輸出其中的值;而*(p++)是先輸出其中的值再讓p向後移一單元。但是,printf函數是從右向左計算參數表的,所以先計算的是*(++p)。這樣,p就從指向a[1]變為指向a[2]了;然後再計算*(p++),由於是後++,所以輸出還是a[2];然後才作p++操作。所以輸出兩次a[2],最後p指向a[3].
5. C語言指針問題,求詳解!!
feofSee Alsoclearerr
| ferror
Requirements
OS Versions: Windows CE 2.0 and later.
Header:
stdlib.h.
Link Library: coredll.dll.
Tests for end-of-file on a stream.
int feof( FILE* stream
);Parametersstream
Pointer to FILE structure. Return Values
The feof function returns a nonzero value after the first read
operation that attempts to read past the end of the file.
It returns 0 if the current position is not end of file.
There is no error return.
Remarks
The feof routine (implemented both as a function and as a macro)
determines whether the end of stream has been reached.
When end of file is reached, read operations return an end-of-file indicator
until the stream is closed or until fsetpos, fseek, or
clearerr is called against it.
Example
/* FEOF.C: This program uses feof to indicate when
* it reaches the end of the file FEOF.C. It also
* checks for errors with ferror.
*/
#include <stdio.h>
#include <stdlib.h>
void main( void )
{
int count, total = 0;
char buffer[100];
FILE *stream;
if( (stream = fopen( "feof.c", "r" )) == NULL )
exit( 1 );
/* Cycle until end of file reached: */
while( !feof( stream ) )
{
/* Attempt to read in 10 bytes: */
count = fread( buffer, sizeof( char ), 100, stream );
if( ferror( stream ) ) {
printf( "Read error" );
break;
}
/* Total up actual bytes read */
total += count;
}
printf( "Number of bytes read = %d\n", total );
fclose( stream );
}
Output
Number of bytes read = 745Requirements
OS Versions: Windows CE 2.0 and later.
Header:
stdlib.h.
Link Library: coredll.dll.
See Also
clearerr | ferror
Last updated on Wednesday, September 14, 2005
© 2005
Microsoft Corporation. All rights reserved.
6. c語言中 &= 是什麼意思
按位與後賦值運算符
7. c語言中指針怎麼使用
1、使用場景
使用指針時,必須將它指向一個變數的地址或者為它分配空間方能使用,如下所示:
#include<stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[])
{
int a[5]={0,1,2,3,4};
int *b,*d;
int c=2;
int *e=a; //e指向a數組首地址
//*b=2; 無法直接初始化
//printf("%d ", *b);
e=e+2; //移動兩個地址單元
d=&c; //d指向c的地址來表示值
c=4; //修改原c變數的值,d指針的值會發生改變
b=(int *)malloc(sizeof(int));//為b分配一個int型空間來直接存儲值
*b=2;//分配空間後可以直接賦值了
printf("this is e,b,c,d :%d %d %d %d ",*e,*b,c,*d);
2、類型說明
(1)int *a :表示一個指向int型變數的指針,指向的是變數的地址單元
(2)char *b:表示一個指向char變數的指針
*a表示的是這個指針指向地址的值,a為此指針本身的地址,這點要明確,一般用*(a+1)、*(a+2)來表示值,如:
int nums[5]={0,1,2,3,4};
int *a=nums;
printf("%d %d %p ",*a,*(a+1),a);
(7)c語言指針中and擴展閱讀:
指針的運算
指針指向變數地址,若原變數的內容發生了變化,它本身也會發生變化,指針之間的運算一般為值運算和地址運算
(1)值運算:直接通過*運算方式,像a+*(a+1),結果為第一個元素與第二個元素相加。
int nums[5]={0,1,2,3,4};
int *a=nums;
(2)地址運算:通過a+i的方式.指針會指向a的下i個地址。
int nums[5]={0,1,2,3,4};
int *a=nums;
a=a+2;
printf("%d ",*a);
結果輸出2。