C language test questions 2

Publisher:创新之星Latest update time:2015-12-22 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
1. Please write a C function that searches for a given character in a given memory area and returns the index value of the character's location.
 
Answer:
int search(char *cpSource, int n, char ch)
{
        int i;
        for(i=0; i         return i;
}
 
2. A singly linked list, with an unknown head node, and a pointer pointing to one of the nodes. How to delete the node pointed to by this pointer?
 
Answer:
Copy the value of the next node pointed to by this pointer to this node, set next to next->next, and then delete the node pointed to by next.
 
3. Write a function to compare the sizes of two strings str1 and str2. If they are equal, it returns 0; if str1 is greater than str2, it returns 1; if str1 is less than str2, it returns -1.
 
Answer:
int strcmp ( const char * src,const char * dst)
{
       int ret = 0 ;
       while( ! (ret = *(unsigned char *)src - *(unsigned char *)dst) && *dst)
       {
               ++src;
               ++dst;
        }
       if ( ret < 0 )
               ret = -1 ;
       else if ( ret > 0 )
               ret = 1 ;
       return( ret );

}
 
Reference address:C language test questions 2

Previous article:C language test questions five
Next article:C language test questions 4

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号