PROGRAMMAZIONE I A.A. 2017/2018

Similar documents
PROGRAMMAZIONE I A.A. 2018/2019

CSE 374 Programming Concepts & Tools

Should you know scanf and printf?

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Programming in C. What is C?... What is C?

Programming in C UVic SEng 265

Programming in C. What is C?... What is C?

Chapter 11 Introduction to Programming in C

PROGRAMMAZIONE I A.A. 2017/2018

CSE 303: Concepts and Tools for Software Development

Computer Science & Information Technology (CS) Rank under AIR 100. Examination Oriented Theory, Practice Set Key concepts, Analysis & Summary

Chapter 11 Introduction to Programming in C

Chapter 11 Introduction to Programming in C

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Chapter 11 Introduction to Programming in C

Chapter 11 Introduction to Programming in C

CSE 303 Lecture 8. Intro to C programming

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

Introduction to C. CS2023 Winter 2004

Two s Complement Review. Two s Complement Review. Agenda. Agenda 6/21/2011

C Review. MaxMSP Developers Workshop Summer 2009 CNMAT

CS 31: Intro to Systems Pointers and Memory. Martin Gagne Swarthmore College February 16, 2016

C Language Coding Standard

Functions in C C Programming and Software Tools. N.C. State Department of Computer Science

PROGRAMMAZIONE I A.A. 2017/2018

Introduction to Computing Lecture 01: Introduction to C

In this session we will cover the following sub-topics: 1.Identifiers 2.Variables 3.Keywords 4.Statements 5.Comments 6.Whitespaces 7.Syntax 8.

Chapter 11 Introduction to Programming in C

Multiple Choice Questions ( 1 mark)

Basic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C / C++ Coding Rules

C Concepts - I/O. Lecture 19 COP 3014 Fall November 29, 2017

Model Viva Questions for Programming in C lab

In the case of the dynamic array, the space must be deallocated when the program is finished with it. free(x);

Procedures, Parameters, Values and Variables. Steven R. Bagley

CSE 124 Discussion (10/3) C/C++ Basics

CS102: Standard I/O. %<flag(s)><width><precision><size>conversion-code

Slide Set 1. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

Outline. Computer programming. Debugging. What is it. Debugging. Hints. Debugging

Array Initialization

C/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock)

C/Java Syntax. Lecture 02 Summary. Keywords Variable Declarations Data Types Operators Statements. Functions. if, switch, while, do-while, for

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

Worksheet 4 Basic Input functions and Mathematical Operators

!"#$% &'($) *+!$ 0!'" 0+'&"$.&0-2$ 10.+3&2),&/3+, %&&/3+, C,-"!.&/+"*0.&('1 :2 %*10% *%7)/ 30'&. 0% /4%./

Programming in C week 1 meeting Tiina Niklander

Variables in C. Variables in C. What Are Variables in C? CMSC 104, Fall 2012 John Y. Park

8. Characters, Strings and Files

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

Lab Exam 1 D [1 mark] Give an example of a sample input which would make the function

Fundamental of Programming (C)

Programming in C First meeting

C: How to Program. Week /Mar/05

Introduction to C. Robert Escriva. Cornell CS 4411, August 30, Geared toward programmers

Special PRG Lecture No. 2. Professor David Brailsford Special PRG Lecture: Arrays

CS113: Lecture 7. Topics: The C Preprocessor. I/O, Streams, Files

CS Introduction to Programming Midterm Exam #2 - Prof. Reed Fall 2015

C programming basics T3-1 -

Topic 8: I/O. Reading: Chapter 7 in Kernighan & Ritchie more details in Appendix B (optional) even more details in GNU C Library manual (optional)

C Introduction. Comparison w/ Java, Memory Model, and Pointers

C Input/Output. Before we discuss I/O in C, let's review how C++ I/O works. int i; double x;

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

C++ for Java Programmers

Linked-List Basic Examples. A linked-list is Linear collection of self-referential class objects, called nodes Connected by pointer links

Language Design COMS W4115. Prof. Stephen A. Edwards Spring 2003 Columbia University Department of Computer Science

Slide Set 3. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.

Lecture 02 Summary. C/Java Syntax 1/14/2009. Keywords Variable Declarations Data Types Operators Statements. Functions

notice the '' you must have those around character values, they are not needed for integers or decimals.

COP 3275: Chapter 02. Jonathan C.L. Liu, Ph.D. CISE Department University of Florida, USA

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

Approximately a Test II CPSC 206

CS Prof J.P.Morrison

CS 241 Data Organization Pointers and Arrays

CS113: Lecture 4. Topics: Functions. Function Activation Records

Functions & Memory Maps Review C Programming Language

CS 220: Introduction to Parallel Computing. Beginning C. Lecture 2

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 13, FALL 2012

PROGRAMMAZIONE I A.A. 2017/2018

Introduction to C Programming

Characters in C consist of any printable or nonprintable character in the computer s character set including lowercase letters, uppercase letters,

Subject: Fundamental of Computer Programming 2068

Fundamental of Programming (C)

Variables in C. CMSC 104, Spring 2014 Christopher S. Marron. (thanks to John Park for slides) Tuesday, February 18, 14

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

War Industries Presents: An Introduction to Programming for Hackers Part III - Advanced Variables & Flow Control.

Advanced C Programming Topics

C Programming Review CSC 4320/6320

just a ((somewhat) safer) dialect.

Data types, variables, constants

EC312 Chapter 5: Intro to Pointers

IT 374 C# and Applications/ IT695 C# Data Structures

AMCAT Automata Coding Sample Questions And Answers

CS61C Machine Structures. Lecture 4 C Pointers and Arrays. 1/25/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/

Chapter 3: Arrays and More C Functionality

SWEN-250 Personal SE. Introduction to C

Transcription:

PROGRAMMAZIONE I A.A. 2017/2018

HINTS

PRESENTATION IS POWERFUL int ok = thiscouldgowrong(); if (!ok) fprintf(stderr, "Error: exiting...\n"); return(0); Good presentation does not draw attention or distract; it serves only to reveal the code s intent. This helps programmers work with the code effectively. You can see what the author intended here: return(0) was only to be called when the test failed. But the presentation has hidden the real behaviour: the code will always exit.

LAYOUT Code layout concerns include indentation, use of whitespace around operators, capitalisation, brace placement (be it K&R style, Allman, Whitesmith, or the like), and the age-old tabs versus spaces indent debate Allman while (x == y) { something(); somethingelse(); } Whitesmiths while (x == y) { something(); somethingelse(); } KR while (x == y) { something(); somethingelse(); }

KR The K&R style is commonly used in C (Ritchie designed C). int main(int argc, char *argv[]) { /*...*/ while (x == y) { something(); somethingelse(); } if (some_error) do_correct(); else continue_as_usual(); } finalthing(); /*...*/

NAMES A name conveys the identity of an object; it describes the thing, indicates its behaviour and intended use. A misnamed variable can be very confusing. Do not create unnecessarily long variable name Do not use underscore as first character to avoid confusion between system variable and user defined variables because many system variables starts with underscore Variable names are case-sensitive. üsum,sum,sum, sum these are different variable names. Reserve words with one/more Capital letters allowed eg. Int, Float, char are allowed but try to skip them.

NAMING CONVENTION See the difference üa = b * c; üweekly_pay = hours_worked * pay_rate; Struct Struct Members Enum Enum Members Trivial variables Local variables Pointers Global variables TitleCase lower_case or lowercase ETitleCase ALL_CAPS i,x,n,f etc... lower_case or lowercase p_lowercase or p_lower_case g_lowercase or g_lower_case

WRITE LESS CODE More code means there is more to read and more to understand it makes our programs harder to comprehend. The more code there is, the more work is required to make modifications the program is harder to modify. Code harbours bugs. The more code you have, the more places there are for bugs to hide.

EXAMPLE A simple and common class of pointless code is the unnecessary use of conditional statements and tautological logic constructs. if (expression) return 1; else return 0; return expression; if (something!= 0) { //... } if (something) { //... }

COMMENTS Add comments as more as you can For instance, before each function declaration to let understand other programmers what they do with the parameters they take as input. But there are also stupid comments: ++i; // increment i // loop over all items, and add them up int total = 0; for (int n = 0; n < MAX; n++) { total += items[n]; }

SCANF

PROBLEMS WITH SCANF Example scanf.c Input buffer #include <stdio.h> int main() { char a, b; int c= 0; printf("enter a character: "); scanf("%c", &a); d \n printf("enter a character: "); scanf("%c", &b); printf("enter an int: "); scanf("%d", &c); } return 0; MacBook-Francesco:ProgrammI francescosantini$./scanf Enter a character: d Enter a character: Enter an int: 5

SOLUTION #include <stdio.h> int main() { char a, b; int c= 0; printf("enter a character: "); scanf("%c", &a); printf("enter a character: "); scanf( %c", &b); printf("enter an int: "); scanf("%d", &c); } return 0;

FGETS #include<stdio.h> int main(void) { char a[10]; if (fgets (a, 10, stdin) == NULL) printf("error\n"); } printf("%s", a); MacBook-Francesco:ProgrammI francescosantini$./fgets abcdefghilmnopq abcdefghi

WHY C (C++)

POPULARITY (2016) https://blog.newrelic.com/2016/08/18/popul ar-programming-languages-2016-go/

ONE MORE CHART http://pypl.github.io/pypl.html

QUOTATIONS So what do all these data points add up to? Java remains incredibly popular, and job seekers can t go wrong learning it. JavaScript skills may not land you a job as quickly, but you ll be in good company with legions of other programmers. There s still interest in the various flavors of C as well, and PHP plays a big role in the mid-market. But perhaps the real takeaway is that we seem to be moving into a polyglot world where organizations increasingly employ multiple languages. The idea is to take advantage of each language s special strengths as well as the varied expertise of the programming team.

WEB http://spectrum.ieee.org/static/interactivethe-top-programming-languages-2016

ENTERPRISE

EMBEDDED

C PERFORMANCE

WHY C IS FASTER Newer languages which have support for garbage collection, dynamic typing and other facilities which make it easier for the programmer to write programs. The catch is, there is additional processing overhead which will degrade the performance of the application. C doesn't have any of that, which means that there is no overhead. üthat means that the programmer needs to be able to allocate memory and free them to prevent memory leaks, and must deal with static typing of variables.

BITCORE https://bitcore.io

JOBS

JOBS

JOBS

ARDUINO/GENUINO

INTRO https://www.arduino.cc Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing something online. You can tell your board what to do by sending a set of instructions to the microcontroller on the board. Arduino was born at the Ivrea Interaction Design Institute as an easy tool for fast prototyping, aimed at students without a background in electronics and programming.

ARDUINO A worldwide community of makers - students, hobbyists, artists, programmers, and professionals It runs on Mac, Windows, and Linux Arduino Programming Language ühttps://www.arduino.cc/en/reference/homepage Examples ühttps://youtu.be/eid1lnpm_24 (http://tinyurl.com/huwmec8) ühttps://youtu.be/f4wua8h0cpo