summaryrefslogtreecommitdiff
path: root/Let_us_C
diff options
context:
space:
mode:
Diffstat (limited to 'Let_us_C')
-rwxr-xr-x[-rw-r--r--]Let_us_C/README.txt0
-rwxr-xr-x[-rw-r--r--]Let_us_C/chapter-1.ipynb0
-rwxr-xr-x[-rw-r--r--]Let_us_C/chapter-10.ipynb0
-rwxr-xr-x[-rw-r--r--]Let_us_C/chapter-11.ipynb0
-rwxr-xr-x[-rw-r--r--]Let_us_C/chapter-12.ipynb0
-rwxr-xr-x[-rw-r--r--]Let_us_C/chapter-13.ipynb0
-rwxr-xr-x[-rw-r--r--]Let_us_C/chapter-14.ipynb0
-rwxr-xr-x[-rw-r--r--]Let_us_C/chapter-15.ipynb1203
-rwxr-xr-x[-rw-r--r--]Let_us_C/chapter-16.ipynb0
-rwxr-xr-x[-rw-r--r--]Let_us_C/chapter-17.ipynb0
-rwxr-xr-x[-rw-r--r--]Let_us_C/chapter-18.ipynb0
-rwxr-xr-x[-rw-r--r--]Let_us_C/chapter-2.ipynb0
-rwxr-xr-x[-rw-r--r--]Let_us_C/chapter-20.ipynb0
-rwxr-xr-x[-rw-r--r--]Let_us_C/chapter-21.ipynb0
-rwxr-xr-x[-rw-r--r--]Let_us_C/chapter-3.ipynb0
-rwxr-xr-x[-rw-r--r--]Let_us_C/chapter-4.ipynb0
-rwxr-xr-x[-rw-r--r--]Let_us_C/chapter-5.ipynb0
-rwxr-xr-x[-rw-r--r--]Let_us_C/chapter-6.ipynb0
-rwxr-xr-x[-rw-r--r--]Let_us_C/chapter-7.ipynb0
-rwxr-xr-x[-rw-r--r--]Let_us_C/chapter-8.ipynb0
-rwxr-xr-x[-rw-r--r--]Let_us_C/chapter-9.ipynb0
-rwxr-xr-x[-rw-r--r--]Let_us_C/screenshots/binary.pngbin30718 -> 30718 bytes
-rwxr-xr-x[-rw-r--r--]Let_us_C/screenshots/hellowindows.pngbin67812 -> 67812 bytes
-rwxr-xr-x[-rw-r--r--]Let_us_C/screenshots/macro.pngbin32392 -> 32392 bytes
24 files changed, 601 insertions, 602 deletions
diff --git a/Let_us_C/README.txt b/Let_us_C/README.txt
index 752b7f71..752b7f71 100644..100755
--- a/Let_us_C/README.txt
+++ b/Let_us_C/README.txt
diff --git a/Let_us_C/chapter-1.ipynb b/Let_us_C/chapter-1.ipynb
index 215baac9..215baac9 100644..100755
--- a/Let_us_C/chapter-1.ipynb
+++ b/Let_us_C/chapter-1.ipynb
diff --git a/Let_us_C/chapter-10.ipynb b/Let_us_C/chapter-10.ipynb
index 7257e56a..7257e56a 100644..100755
--- a/Let_us_C/chapter-10.ipynb
+++ b/Let_us_C/chapter-10.ipynb
diff --git a/Let_us_C/chapter-11.ipynb b/Let_us_C/chapter-11.ipynb
index 697d86a1..697d86a1 100644..100755
--- a/Let_us_C/chapter-11.ipynb
+++ b/Let_us_C/chapter-11.ipynb
diff --git a/Let_us_C/chapter-12.ipynb b/Let_us_C/chapter-12.ipynb
index a3331f4d..a3331f4d 100644..100755
--- a/Let_us_C/chapter-12.ipynb
+++ b/Let_us_C/chapter-12.ipynb
diff --git a/Let_us_C/chapter-13.ipynb b/Let_us_C/chapter-13.ipynb
index bd79a9c1..bd79a9c1 100644..100755
--- a/Let_us_C/chapter-13.ipynb
+++ b/Let_us_C/chapter-13.ipynb
diff --git a/Let_us_C/chapter-14.ipynb b/Let_us_C/chapter-14.ipynb
index 8181a680..8181a680 100644..100755
--- a/Let_us_C/chapter-14.ipynb
+++ b/Let_us_C/chapter-14.ipynb
diff --git a/Let_us_C/chapter-15.ipynb b/Let_us_C/chapter-15.ipynb
index 087a08d0..993f6a9b 100644..100755
--- a/Let_us_C/chapter-15.ipynb
+++ b/Let_us_C/chapter-15.ipynb
@@ -1,603 +1,602 @@
-{
- "metadata": {
- "name": "",
- "signature": "sha256:d98d61d8802af6f3fda8e30c6e47e6355ba4d55d204c760c90ae2fa05295236c"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h1>Chapter 15: Miscellaneous Features <h1>"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>Enumerated Data Type , Page number: 508<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "\n",
- "def enum(**enums):\n",
- " return type('Enum', (), enums)\n",
- "#Enum declaration\n",
- "emp_dept = enum(assembly = 0, manufacturing = 1,accounts = 2, stores = 3)\n",
- "\n",
- "from collections import namedtuple\n",
- "#Structure declaration\n",
- "struct_employee = namedtuple(\"struct_employee\", \"name age bs emp_dept\")\n",
- "\n",
- "\n",
- "#Structure for employee\n",
- "department = emp_dept.manufacturing\n",
- "e = struct_employee(\"Lothar Mattheus\",28,5575.50,department)\n",
- "\n",
- "#Result\n",
- "print \"Name = \",e.name\n",
- "print \"Age = \",e.age\n",
- "print \"Basic salary = \",e.bs\n",
- "print \"Dept = \",e.emp_dept\n",
- "\n",
- "if(e.emp_dept == 2):\n",
- " print \"%s is an accountant\" %(e.name)\n",
- "else:\n",
- " print \"%s is not an accountant\" %(e.name)\n",
- " \n",
- " \n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Name = Lothar Mattheus\n",
- "Age = 28\n",
- "Basic salary = 5575.5\n",
- "Dept = 1\n",
- "Lothar Mattheus is not an accountant\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>Are Enums Necessary, Page number: 510<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "\n",
- "#macro definition\n",
- "ASSEMBLY = 0\n",
- "MANUFACTURING = 1\n",
- "ACCOUNTS = 2\n",
- "STORES = 3\n",
- "\n",
- "from collections import namedtuple\n",
- "#Structure declaration\n",
- "struct_employee = namedtuple(\"struct_employee\", \"name age bs department\")\n",
- "\n",
- "#Structure for employee\n",
- "e = struct_employee(\"Lothar Mattheus\",28,5575.50,MANUFACTURING)\n",
- "\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [],
- "prompt_number": 2
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>Division Without Typecasting , Page number: 513<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "\n",
- "#Variable declaration\n",
- "x=6\n",
- "y=4\n",
- "\n",
- "#Calculation\n",
- "a = int( x/y) \n",
- "\n",
- "#Result\n",
- "print \"Value of a = %f\" %(a)\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Value of a = 1.000000\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>Division With Typecasting , Page number: 513<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "\n",
- "#Variable declaration\n",
- "x=6\n",
- "y=4\n",
- "\n",
- "#Calculation\n",
- "a = float( x)/y\n",
- "\n",
- "#Result\n",
- "print \"Value of a = %f\" %(a)\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Value of a = 1.500000\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>Type Casting , Page number: 514<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "\n",
- "#Variable declaration\n",
- "a=6.35\n",
- "\n",
- "#Result\n",
- "print \"Value of a on typecasting = %d\" %(int(a))\n",
- "print \"Value of a = %f\"%(a)\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Value of a on typecasting = 6\n",
- "Value of a = 6.350000\n"
- ]
- }
- ],
- "prompt_number": 7
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>Bit Fields , Page number: 516<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "\n",
- "from ctypes import *\n",
- "import ctypes\n",
- "import math\n",
- "\n",
- "#macro definition\n",
- "MALE = 0\n",
- "FEMALE = 1\n",
- "SINGLE = 0\n",
- "MARRIED = 1\n",
- "DIVORCED = 2\n",
- "WIDOWED = 3\n",
- "\n",
- "#Structure declaration\n",
- "class employee(Structure):\n",
- " _fields_ = [(\"gender\", c_int, 1),(\"mar_stat\", c_int, 3),(\"hobby\", c_int, 3),(\"scheme\", c_int, 4)]\n",
- " _sizeof_ = 2\n",
- "#Structure for employee\n",
- "e = employee()\n",
- "e.gender = MALE\n",
- "e.mar_stat = DIVORCED\n",
- "e.hobby = 5\n",
- "e.scheme =9\n",
- "\n",
- "#Result\n",
- "print \"Gender = \",e.gender\n",
- "print \"Marital status = \",e.mar_stat\n",
- "print \"Bytes occupied by e = \",sizeof(e)\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Gender = 0\n",
- "Marital status = 2\n",
- "Bytes occupied by e = 4\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>Address of a Function , Page number: 517<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "\n",
- "#Function definition\n",
- "def display():\n",
- " print \"Long live viruses!!\"\n",
- "\n",
- "#Result\n",
- "print \"Address of function display is \",id(display)\n",
- "display() #function call\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Address of function display is 133993192\n",
- "Long live viruses!!\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>Invoking a Function Using Pointer, Page number: 518<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "\n",
- "#Function definition\n",
- "def display():\n",
- " print \"Long live viruses!!\"\n",
- "\n",
- "func_ptr = id(display) #assigning address of function\n",
- "print \"Address of function display is \",func_ptr\n",
- "display() #function call\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Address of function display is 133993080\n",
- "Long live viruses!!\n"
- ]
- }
- ],
- "prompt_number": 10
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>Functions Returning Pointers , Page number: 520<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "\n",
- "#Function definition\n",
- "def fun():\n",
- " i = 20\n",
- " return (i)\n",
- "\n",
- "#Result\n",
- "p =fun() #function call\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [],
- "prompt_number": 11
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>String Copy , Page number: 520<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "\n",
- "#Function definition\n",
- "def copy(t,s):\n",
- " i = 0\n",
- " while ( s[i] != '\\0' ):\n",
- " t = t + s[i]\n",
- " i = i + 1\n",
- " return t\n",
- "\n",
- "#Variable declaration\n",
- "source = \"Jaded\\0\" \n",
- "target = ''\n",
- "string = copy( target, source ) # function call\n",
- "\n",
- "#Result\n",
- "print string\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Jaded\n"
- ]
- }
- ],
- "prompt_number": 12
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>Findmax Function , Page number: 522<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "\n",
- "\n",
- "#function declaration\n",
- "def findmax(*arg):\n",
- " maxi = arg[1]\n",
- " for count in range(2,arg[0]):\n",
- " num = arg[count]\n",
- " if (num > maxi):\n",
- " maxi = num\n",
- " return maxi\n",
- "\n",
- "maxi = findmax(5,23,15,1,92,50)#function call \n",
- "print \"maximum = \",maxi\n",
- "\n",
- "maxi = findmax(3,100,300,29)#function call \n",
- "print \"maximum = \",maxi\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "maximum = 92\n",
- "maximum = 300\n"
- ]
- }
- ],
- "prompt_number": 13
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>Display Function, Page number: 524<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "\n",
- "#function declaration\n",
- "def display(*arg):\n",
- " if(arg[0] == 1): #case int\n",
- " for j in range(2,arg[1]+2):\n",
- " i = arg[j]\n",
- " print \"%d\"%(i)\n",
- " elif(arg[0] == 2): #case char\n",
- " for j in range(2,arg[1]+2):\n",
- " i = arg[j]\n",
- " print \"%c\"%(i)\n",
- " elif(arg[0] == 3): #case double\n",
- " for j in range(2,arg[1]+2):\n",
- " i = arg[j]\n",
- " print \"%lf\"%(i)\n",
- " \n",
- "#function calls\n",
- "display(1,2,5,6)\n",
- "display(2,4,'A','a','b','c')\n",
- "display(3,3,2.5,299.3,-1.0)\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "5\n",
- "6\n",
- "A\n",
- "a\n",
- "b\n",
- "c\n",
- "2.500000\n",
- "299.300000\n",
- "-1.000000\n"
- ]
- }
- ],
- "prompt_number": 14
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>Union Demo , Page number: 526<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "\n",
- "from ctypes import *\n",
- "\n",
- "#union declaration\n",
- "class union_a(Union):\n",
- " _fields_ = [(\"i\", c_int),\n",
- " (\"ch\", ((c_char * 1)*2))]\n",
- "\n",
- "key = union_a()\n",
- "key.i = 512\n",
- "print \"key.i = \",key.i\n",
- "print \"key.ch[0] = \",(key.ch[0][0])\n",
- "print \"key.ch[1] = \",(key.ch[1][0])\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": []
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>Union Example , Page number: 530<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "\n",
- "from ctypes import *\n",
- "\n",
- "#Union declaration\n",
- "class union_a(Union):\n",
- " _fields_ = [(\"i\", c_int),\n",
- " (\"ch\", ((c_char * 1)*2))]\n",
- "\n",
- "key = union_a()\n",
- "key.i = 512\n",
- "print \"key.i = \",key.i\n",
- "print \"key.ch[0] = \",(key.ch[0][0])\n",
- "print \"key.ch[1] = \",(key.ch[1][0])\n",
- "\n",
- "key.ch[0][0] = 50 #assign new value to key.ch[0]\n",
- "print\"key.i = \",key.i\n",
- "print\"key.ch[0] = \",(key.ch[0][0])\n",
- "print\"key.ch[1] = \",(key.ch[1][0])\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": []
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<h3>Union of Structures , Page number: 531<h3>"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "\n",
- "from ctypes import *\n",
- "\n",
- "#Structure declarations\n",
- "class a(Structure):\n",
- " _fields_ = [(\"i\", c_int),\n",
- " (\"c\", ((c_char * 1)*2))]\n",
- "\n",
- "class b(Structure):\n",
- " _fields_ = [(\"j\", c_int),\n",
- " (\"d\", ((c_char * 1)*2))]\n",
- " \n",
- "#Union declaration\n",
- "class union_z(Union):\n",
- " _fields_ = [(\"key\", a),\n",
- " (\"data\", b )]\n",
- "\n",
- "strange = union_z()\n",
- "strange.key.i = 512\n",
- "strange.data.d[0][0] = 0\n",
- "strange.data.d[1][0] = 32\n",
- "\n",
- "print strange.key.i\n",
- "print strange.data.j\n",
- "print strange.key.c[0][0]\n",
- "print strange.data.d[0][0]\n",
- "print strange.key.c[1][0]\n",
- "print strange.data.d[1][0]\n"
- ],
- "language": "python",
- "metadata": {},
- "outputs": []
- }
- ],
- "metadata": {}
- }
- ]
+{
+ "metadata": {
+ "name": "chapter-15.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 15: Miscellaneous Features <h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Enumerated Data Type , Page number: 508<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "def enum(**enums):\n",
+ " return type('Enum', (), enums)\n",
+ "#Enum declaration\n",
+ "emp_dept = enum(assembly = 0, manufacturing = 1,accounts = 2, stores = 3)\n",
+ "\n",
+ "from collections import namedtuple\n",
+ "#Structure declaration\n",
+ "struct_employee = namedtuple(\"struct_employee\", \"name age bs emp_dept\")\n",
+ "\n",
+ "\n",
+ "#Structure for employee\n",
+ "department = emp_dept.manufacturing\n",
+ "e = struct_employee(\"Lothar Mattheus\",28,5575.50,department)\n",
+ "\n",
+ "#Result\n",
+ "print \"Name = \",e.name\n",
+ "print \"Age = \",e.age\n",
+ "print \"Basic salary = \",e.bs\n",
+ "print \"Dept = \",e.emp_dept\n",
+ "\n",
+ "if(e.emp_dept == 2):\n",
+ " print \"%s is an accountant\" %(e.name)\n",
+ "else:\n",
+ " print \"%s is not an accountant\" %(e.name)\n",
+ " \n",
+ " \n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Name = Lothar Mattheus\n",
+ "Age = 28\n",
+ "Basic salary = 5575.5\n",
+ "Dept = 1\n",
+ "Lothar Mattheus is not an accountant\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Are Enums Necessary, Page number: 510<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#macro definition\n",
+ "ASSEMBLY = 0\n",
+ "MANUFACTURING = 1\n",
+ "ACCOUNTS = 2\n",
+ "STORES = 3\n",
+ "\n",
+ "from collections import namedtuple\n",
+ "#Structure declaration\n",
+ "struct_employee = namedtuple(\"struct_employee\", \"name age bs department\")\n",
+ "\n",
+ "#Structure for employee\n",
+ "e = struct_employee(\"Lothar Mattheus\",28,5575.50,MANUFACTURING)\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Division Without Typecasting , Page number: 513<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#Variable declaration\n",
+ "x=6\n",
+ "y=4\n",
+ "\n",
+ "#Calculation\n",
+ "a = int( x/y) \n",
+ "\n",
+ "#Result\n",
+ "print \"Value of a = %f\" %(a)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of a = 1.000000\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Division With Typecasting , Page number: 513<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#Variable declaration\n",
+ "x=6\n",
+ "y=4\n",
+ "\n",
+ "#Calculation\n",
+ "a = float( x)/y\n",
+ "\n",
+ "#Result\n",
+ "print \"Value of a = %f\" %(a)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of a = 1.500000\n"
+ ]
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Type Casting , Page number: 514<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#Variable declaration\n",
+ "a=6.35\n",
+ "\n",
+ "#Result\n",
+ "print \"Value of a on typecasting = %d\" %(int(a))\n",
+ "print \"Value of a = %f\"%(a)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Value of a on typecasting = 6\n",
+ "Value of a = 6.350000\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Bit Fields , Page number: 516<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "from ctypes import *\n",
+ "import ctypes\n",
+ "import math\n",
+ "\n",
+ "#macro definition\n",
+ "MALE = 0\n",
+ "FEMALE = 1\n",
+ "SINGLE = 0\n",
+ "MARRIED = 1\n",
+ "DIVORCED = 2\n",
+ "WIDOWED = 3\n",
+ "\n",
+ "#Structure declaration\n",
+ "class employee(Structure):\n",
+ " _fields_ = [(\"gender\", c_int, 1),(\"mar_stat\", c_int, 3),(\"hobby\", c_int, 3),(\"scheme\", c_int, 4)]\n",
+ " _sizeof_ = 2\n",
+ "#Structure for employee\n",
+ "e = employee()\n",
+ "e.gender = MALE\n",
+ "e.mar_stat = DIVORCED\n",
+ "e.hobby = 5\n",
+ "e.scheme =9\n",
+ "\n",
+ "#Result\n",
+ "print \"Gender = \",e.gender\n",
+ "print \"Marital status = \",e.mar_stat\n",
+ "print \"Bytes occupied by e = \",sizeof(e)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Gender = 0\n",
+ "Marital status = 2\n",
+ "Bytes occupied by e = 4\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Address of a Function , Page number: 517<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#Function definition\n",
+ "def display():\n",
+ " print \"Long live viruses!!\"\n",
+ "\n",
+ "#Result\n",
+ "print \"Address of function display is \",id(display)\n",
+ "display() #function call\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Address of function display is 133993192\n",
+ "Long live viruses!!\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Invoking a Function Using Pointer, Page number: 518<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#Function definition\n",
+ "def display():\n",
+ " print \"Long live viruses!!\"\n",
+ "\n",
+ "func_ptr = id(display) #assigning address of function\n",
+ "print \"Address of function display is \",func_ptr\n",
+ "display() #function call\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Address of function display is 133993080\n",
+ "Long live viruses!!\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Functions Returning Pointers , Page number: 520<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#Function definition\n",
+ "def fun():\n",
+ " i = 20\n",
+ " return (i)\n",
+ "\n",
+ "#Result\n",
+ "p =fun() #function call\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>String Copy , Page number: 520<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#Function definition\n",
+ "def copy(t,s):\n",
+ " i = 0\n",
+ " while ( s[i] != '\\0' ):\n",
+ " t = t + s[i]\n",
+ " i = i + 1\n",
+ " return t\n",
+ "\n",
+ "#Variable declaration\n",
+ "source = \"Jaded\\0\" \n",
+ "target = ''\n",
+ "string = copy( target, source ) # function call\n",
+ "\n",
+ "#Result\n",
+ "print string\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Jaded\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Findmax Function , Page number: 522<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "to find out max value from a set of values\n",
+ "\n",
+ "#function declaration\n",
+ "def findmax(*arg):\n",
+ " maxi = arg[1]\n",
+ " for count in range(2,arg[0]):\n",
+ " num = arg[count]\n",
+ " if (num > maxi):\n",
+ " maxi = num\n",
+ " return maxi\n",
+ "\n",
+ "maxi = findmax(5,23,15,1,92,50)#function call \n",
+ "print \"maximum = \",maxi\n",
+ "\n",
+ "maxi = findmax(3,100,300,29)#function call \n",
+ "print \"maximum = \",maxi\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "maximum = 92\n",
+ "maximum = 300\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Display Function, Page number: 524<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "#function declaration\n",
+ "def display(*arg):\n",
+ " if(arg[0] == 1): #case int\n",
+ " for j in range(2,arg[1]+2):\n",
+ " i = arg[j]\n",
+ " print \"%d\"%(i)\n",
+ " elif(arg[0] == 2): #case char\n",
+ " for j in range(2,arg[1]+2):\n",
+ " i = arg[j]\n",
+ " print \"%c\"%(i)\n",
+ " elif(arg[0] == 3): #case double\n",
+ " for j in range(2,arg[1]+2):\n",
+ " i = arg[j]\n",
+ " print \"%lf\"%(i)\n",
+ " \n",
+ "#function calls\n",
+ "display(1,2,5,6)\n",
+ "display(2,4,'A','a','b','c')\n",
+ "display(3,3,2.5,299.3,-1.0)\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "5\n",
+ "6\n",
+ "A\n",
+ "a\n",
+ "b\n",
+ "c\n",
+ "2.500000\n",
+ "299.300000\n",
+ "-1.000000\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Union Demo , Page number: 526<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "from ctypes import *\n",
+ "\n",
+ "#union declaration\n",
+ "class union_a(Union):\n",
+ " _fields_ = [(\"i\", c_int),\n",
+ " (\"ch\", ((c_char * 1)*2))]\n",
+ "\n",
+ "key = union_a()\n",
+ "key.i = 512\n",
+ "print \"key.i = \",key.i\n",
+ "print \"key.ch[0] = \",(key.ch[0][0])\n",
+ "print \"key.ch[1] = \",(key.ch[1][0])\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Union Example , Page number: 530<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "from ctypes import *\n",
+ "\n",
+ "#Union declaration\n",
+ "class union_a(Union):\n",
+ " _fields_ = [(\"i\", c_int),\n",
+ " (\"ch\", ((c_char * 1)*2))]\n",
+ "\n",
+ "key = union_a()\n",
+ "key.i = 512\n",
+ "print \"key.i = \",key.i\n",
+ "print \"key.ch[0] = \",(key.ch[0][0])\n",
+ "print \"key.ch[1] = \",(key.ch[1][0])\n",
+ "\n",
+ "key.ch[0][0] = 50 #assign new value to key.ch[0]\n",
+ "print\"key.i = \",key.i\n",
+ "print\"key.ch[0] = \",(key.ch[0][0])\n",
+ "print\"key.ch[1] = \",(key.ch[1][0])\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Union of Structures , Page number: 531<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "\n",
+ "from ctypes import *\n",
+ "\n",
+ "#Structure declarations\n",
+ "class a(Structure):\n",
+ " _fields_ = [(\"i\", c_int),\n",
+ " (\"c\", ((c_char * 1)*2))]\n",
+ "\n",
+ "class b(Structure):\n",
+ " _fields_ = [(\"j\", c_int),\n",
+ " (\"d\", ((c_char * 1)*2))]\n",
+ " \n",
+ "#Union declaration\n",
+ "class union_z(Union):\n",
+ " _fields_ = [(\"key\", a),\n",
+ " (\"data\", b )]\n",
+ "\n",
+ "strange = union_z()\n",
+ "strange.key.i = 512\n",
+ "strange.data.d[0][0] = 0\n",
+ "strange.data.d[1][0] = 32\n",
+ "\n",
+ "print strange.key.i\n",
+ "print strange.data.j\n",
+ "print strange.key.c[0][0]\n",
+ "print strange.data.d[0][0]\n",
+ "print strange.key.c[1][0]\n",
+ "print strange.data.d[1][0]\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
} \ No newline at end of file
diff --git a/Let_us_C/chapter-16.ipynb b/Let_us_C/chapter-16.ipynb
index 195741f0..195741f0 100644..100755
--- a/Let_us_C/chapter-16.ipynb
+++ b/Let_us_C/chapter-16.ipynb
diff --git a/Let_us_C/chapter-17.ipynb b/Let_us_C/chapter-17.ipynb
index ea406a32..ea406a32 100644..100755
--- a/Let_us_C/chapter-17.ipynb
+++ b/Let_us_C/chapter-17.ipynb
diff --git a/Let_us_C/chapter-18.ipynb b/Let_us_C/chapter-18.ipynb
index 3aa35505..3aa35505 100644..100755
--- a/Let_us_C/chapter-18.ipynb
+++ b/Let_us_C/chapter-18.ipynb
diff --git a/Let_us_C/chapter-2.ipynb b/Let_us_C/chapter-2.ipynb
index b7409b44..b7409b44 100644..100755
--- a/Let_us_C/chapter-2.ipynb
+++ b/Let_us_C/chapter-2.ipynb
diff --git a/Let_us_C/chapter-20.ipynb b/Let_us_C/chapter-20.ipynb
index 16c8fdc8..16c8fdc8 100644..100755
--- a/Let_us_C/chapter-20.ipynb
+++ b/Let_us_C/chapter-20.ipynb
diff --git a/Let_us_C/chapter-21.ipynb b/Let_us_C/chapter-21.ipynb
index 9883bc71..9883bc71 100644..100755
--- a/Let_us_C/chapter-21.ipynb
+++ b/Let_us_C/chapter-21.ipynb
diff --git a/Let_us_C/chapter-3.ipynb b/Let_us_C/chapter-3.ipynb
index 5b3de0d9..5b3de0d9 100644..100755
--- a/Let_us_C/chapter-3.ipynb
+++ b/Let_us_C/chapter-3.ipynb
diff --git a/Let_us_C/chapter-4.ipynb b/Let_us_C/chapter-4.ipynb
index fcd96271..fcd96271 100644..100755
--- a/Let_us_C/chapter-4.ipynb
+++ b/Let_us_C/chapter-4.ipynb
diff --git a/Let_us_C/chapter-5.ipynb b/Let_us_C/chapter-5.ipynb
index 2055e966..2055e966 100644..100755
--- a/Let_us_C/chapter-5.ipynb
+++ b/Let_us_C/chapter-5.ipynb
diff --git a/Let_us_C/chapter-6.ipynb b/Let_us_C/chapter-6.ipynb
index ff2bda1a..ff2bda1a 100644..100755
--- a/Let_us_C/chapter-6.ipynb
+++ b/Let_us_C/chapter-6.ipynb
diff --git a/Let_us_C/chapter-7.ipynb b/Let_us_C/chapter-7.ipynb
index 960282bf..960282bf 100644..100755
--- a/Let_us_C/chapter-7.ipynb
+++ b/Let_us_C/chapter-7.ipynb
diff --git a/Let_us_C/chapter-8.ipynb b/Let_us_C/chapter-8.ipynb
index 9467d28a..9467d28a 100644..100755
--- a/Let_us_C/chapter-8.ipynb
+++ b/Let_us_C/chapter-8.ipynb
diff --git a/Let_us_C/chapter-9.ipynb b/Let_us_C/chapter-9.ipynb
index a712e2f0..a712e2f0 100644..100755
--- a/Let_us_C/chapter-9.ipynb
+++ b/Let_us_C/chapter-9.ipynb
diff --git a/Let_us_C/screenshots/binary.png b/Let_us_C/screenshots/binary.png
index 5a14ee93..5a14ee93 100644..100755
--- a/Let_us_C/screenshots/binary.png
+++ b/Let_us_C/screenshots/binary.png
Binary files differ
diff --git a/Let_us_C/screenshots/hellowindows.png b/Let_us_C/screenshots/hellowindows.png
index 622bf2b7..622bf2b7 100644..100755
--- a/Let_us_C/screenshots/hellowindows.png
+++ b/Let_us_C/screenshots/hellowindows.png
Binary files differ
diff --git a/Let_us_C/screenshots/macro.png b/Let_us_C/screenshots/macro.png
index 161b4c74..161b4c74 100644..100755
--- a/Let_us_C/screenshots/macro.png
+++ b/Let_us_C/screenshots/macro.png
Binary files differ