Recitation2.c - Recitation2.c Created by Andrea W on\"<=\"precedes\"=#include\"Recitation2.h\/Mixing signed and unsigned integers in arithmetic

Recitation2.c - Recitation2.c Created by Andrea W...

This preview shows page 1 - 3 out of 4 pages.

//// Recitation2.c// //// Created by Andrea W on 2019/9/12.////"<="precedes "='"#include "Recitation2.h"//Mixing signed and unsigned integers in arithmetic operations//0110, multiply by 2 , add<< will lead to 01100, which multiply by 2#include <stdio.h>int main(void){unsigned int a = 1000;signed int b = -1;//won't compare unsigned int and signed int//in this case signed integer will be automatically converted to a large positive integerif (a > b) puts("a is more than b");else puts("a is less or equal than b");return 0;}//--------------------------------------------------------// Overstepping Array Boundaries// WRONG#include <stdio.h>int main(){int x = 0;int myArray[5] = { 1,2,3,4,5}; //Declaring 5 elements//only position 0-4for(x=1; x<=5; x++) //Looping from 1 till 5.printf("%d\t",myArray[x]);printf("\n");return 0;}//Output: 2 3 4 5 GarbageValue// CORRECT#include <stdio.h>int main(){int x = 0;int myArray[5] = { 1,2,3,4,5}; //Declaring 5 elementsfor(x=0; x<5; x++) //Looping from 0 till 4.printf("%d\t",myArray[x]);
Background image
printf("\n");return 0;}//Output: 1 2 3 4 5//--------------------------------------------------------// Missing out the Base Condition in Recursive Function// WRONG#include <stdio.h>int factorial(int n){return n * factorial(n - 1);//no base case}int main(){
Background image
Image of page 3

You've reached the end of your free preview.

Want to read all 4 pages?

  • Fall '12
  • Barrett
  • Recursion, #define, String literal, return n

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture