Three questions for C language interviews and three questions for C language interviews

Source: Internet
Author: User

Three questions for C language interviews and three questions for C language interviews

1. There are one hundred integers, with a negative number. Find the part with the largest sum of the three consecutive numbers.

Example:

Input: 2,-8, 3,-2, 4,-10

Output: 5 ({3,-2, 4 })

#include
 
   int find(int arr[], int len); int main(void) {    int a[100], b[98], i = 0;    for(i=0; i<100; i++)        scanf("%d", &a[i]);    for(i=0; i<98; i++)    {        b[i] = a[i] + a[i+1] + a[i+2];    }    i = find(b, 98);    printf("%d({%d, %d, %d})\n", b[i], a[i], a[i+1], a[i+2]);} int find(int arr[], int len){    int i = 0, j = 0, tem = 0;    for(i=0; i
  
    arr[i+1] && arr[i] > arr[j])            j = i;    }    i++;    if (arr[i] > arr[j])         j = i;    return j;}
  
 

2. Use <<>>,|,& to implement an unsigned short variable (two bytes) to exchange the high and low bits !!

Example: 0x1234 after switching 0x3412

Function prototype: void func (unsigned short *)

#include
 
   void func(unsigned  short *a);int main(void) {    unsigned  short a = 0x11ff;    func(&a);    printf ("%x\n", a);} void func(unsigned  short *a){    unsigned  short b = *a;    *a = *a << 8;    b = b >> 8;    *a += b;} 
 

3. embedded systems often require programmers to access a specific memory location. In a project, the value of an integer variable with an absolute address of 0x67a9 must be set to 0xaa55.

The compiler is a pure ANSI compiler. Write code to complete this task.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.